jsp with sqlserver

jsp with sqlserver

View Answers

August 4, 2008 at 11:26 AM

Hi friend,


Insert image code

<%@ page language="java" import="java.sql.*,java.util.*,java.io.*,java.awt.image.BufferedImage,java.io.ByteArrayOutputStream,java.io.InputStream,java.text.*" %>

<%

Connection con = null;
String url = "jdbc:mysql://192.168.10.211:3306/";;
String db = "amar";
String driver ="com.mysql.jdbc.Driver";
String userName ="amar" ;
String password ="amar123" ;
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db,userName,password);
PreparedStatement pst = con.prepareStatement("insert into Image values(?,?,?)");
File file = new File("/home/vinod/Desktop/apache-tomcat-6.0.1/webapps/examples/jsp/javabook.gif");
FileInputStream fis = new FileInputStream(file);
pst.setInt(1, 7);
pst.setString(2, "kumar");
pst.setBinaryStream(3,fis,fis.available());
int i = pst.executeUpdate();
if(i!=0){
out.println("image has been inserted");
}
else{
out.println("image is not inserted");
}
}
catch (Exception e){
System.out.println(e);
}

%>

August 4, 2008 at 11:28 AM

retrive image from database code in jsp.

<%@ page language="java" session="true"
import= "
java.awt.image.BufferedImage,java.io.ByteArrayOutputStream,java.io.InputStream,java.sql.Blob,java.sql.Connection,
java.sql.ResultSet,javax.swing.ImageIcon,java.sql.*" %>

<%
try
{
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
}
catch(ClassNotFoundException e)
{ System.out.println(e);
}
String url = "jdbc:mysql://192.168.10.211:3306/";;
String db = "amar";
String userName ="amar" ;
String password ="amar123" ;
Connection con;
con = DriverManager.getConnection(url+db,userName,password);
String query = "SELECT image from Image where id = 7";
out.println(query);
ResultSet rs = con.createStatement().executeQuery(query);
if(rs.next()) {
byte[] bytearray = new byte[4096];
int size=0;
InputStream image;
image = rs.getBinaryStream(1);
response.reset();
response.setContentType("image/gif");
while((size=image.read(bytearray))!= -1 ){
response.getOutputStream().write(bytearray,0,size);
}
response.flushBuffer();
image.close();
rs.close();
}
}
catch (Exception exc)
{ System.out.println(exc);
}

%>
---------------------------------------------

Read for more information.

http://www.roseindia.net/jsp/

Thanks.









Related Tutorials/Questions & Answers:
jsp with sqlserver - JDBC
jsp with sqlserver  Hi everybody, I want to store and retrive images in sqlserver from jsp program. can anybody suggest me the code... code in jsp. --------------------------------------------- Read
ms sqlserver
ms sqlserver  hii, i m getting trouble in restoring a database file in MS SQLServer 2000 . all i have is signature.bkp , query.sql, signaturebackup.bkp files... please guide me how i restore these backup files in new database
Advertisements
ModuleNotFoundError: No module named 'dbt-sqlserver'
ModuleNotFoundError: No module named 'dbt-sqlserver'  Hi, My... 'dbt-sqlserver' How to remove the ModuleNotFoundError: No module named 'dbt-sqlserver' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'easy-sqlserver'
ModuleNotFoundError: No module named 'easy-sqlserver'  Hi, My... named 'easy-sqlserver' How to remove the ModuleNotFoundError: No module named 'easy-sqlserver' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'magical-sqlserver'
ModuleNotFoundError: No module named 'magical-sqlserver'  Hi, My... named 'magical-sqlserver' How to remove the ModuleNotFoundError: No module named 'magical-sqlserver' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'dbt-sqlserver'
ModuleNotFoundError: No module named 'dbt-sqlserver'  Hi, My... 'dbt-sqlserver' How to remove the ModuleNotFoundError: No module named 'dbt-sqlserver' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'django-sqlserver'
ModuleNotFoundError: No module named 'django-sqlserver'  Hi, My... named 'django-sqlserver' How to remove the ModuleNotFoundError: No module named 'django-sqlserver' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'easy-sqlserver'
ModuleNotFoundError: No module named 'easy-sqlserver'  Hi, My... named 'easy-sqlserver' How to remove the ModuleNotFoundError: No module named 'easy-sqlserver' error? Thanks   Hi, In your python
Convert sqlserver database to msexcel
Convert sqlserver database to msexcel  How to i convert sqlserver database values into msexcel sheet using java...   We have used MySQL database. import java.io.*; import java.sql.*; import
Store XML file into Sqlserver Database
Store XML file into Sqlserver Database  Code for storing a typical XML file into SQl server database in 1 or more tables using asp.net using C
Regarding connection between sqlserver 2005 and android application
Regarding connection between sqlserver 2005 and android application  hi to all, i want to know how to create webservice to connect sqlserver 2005 and android. can you please help me by providing source code for ref.. thanks
jsp
org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 7 in the jsp file: /jsp/insertdate.jsp month cannot be resolved 4...(Calendar.MONTH); An error occurred at line: 17 in the jsp file: /jsp
jsp
org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 7 in the jsp file: /jsp/insertdate.jsp month cannot be resolved 4: 5: <% 6: String...); An error occurred at line: 17 in the jsp file: /jsp/insertdate.jsp Duplicate local
Store XML file into Sqlserver Database
Store XML file into Sqlserver Database  Code for storing a typical XML file into SQl server database in 1 or more tables using asp.net using C#. <?xml version="1.0" ?> <!DOCTYPE PubmedArticleSet (View Source
jsp
jsp  how jsp translated into servlets
JSP
JSP  How to run jsp program in eclipse
jsp
jsp  how to create jsp page
Jsp
Jsp  Can I implement interface in jsp
JSP
what is JSP forward tag for  what is JSP forward tag for   It forwards the current request to another JSP page. Below is the syntax for the same:- <jsp:forward page="...url..." /> We can also forward parameter
jsp
jsp  how to include two jsp page
jsp
jsp  how to create a table in oracle using jsp and the table name is entered in text feild of jsp page
jsp
jsp  write a code for jsp file generator to generate a jsp page automatically taking html page as input
JSP
JSP  Hi, What is JSP? What is the use of JSP? Thanks   Hi, JSP Stands for Java Server Pages. It is Java technology for developing web applications. JSP is very easy to learn and it allows the developers to use Java
jsp
jsp   what is the basic necessities reguired for running jsp using JDBC bridge?? and how to write a jsp code to access the detail present in microsoft access pls send link regarding above
Maven Repository/Dependency: org.n52.sensorweb.sos | hibernate-datasource-sqlserver
Maven Repository/Dependency of Group ID org.n52.sensorweb.sos and Artifact ID hibernate-datasource-sqlserver. Latest version of org.n52.sensorweb.sos:hibernate-datasource-sqlserver dependencies. # Version
jsp
jsp  how to pass jsp variable to an html page
JSP
JSP  relevant difference between servlet and jsp in 1 line
jsp
jsp  how to include google map in our jsp page
JSP
JSP   How to create CAPTCHA creation by using JSP? I need an code for CAPTCHA creation by using JSP...   You can create a captcha validation using jsp. Have a look at the following tutorial: Captcha Creation
jsp
jsp  how to write a servlet and jsp program for user login form
jsp
jsp  how to write a servlet and jsp program for user login form
jsp
jsp  why jsp is translated into servlet?pls describe precisly
jsp
jsp  code for jsp automatic genration using html
jsp
jsp  how to write hindi in jsp and store in database as unicode
JSP
JSP  FILE UPLOAD-DOWNLOAD code USING JSP
jsp
jsp  how to delete data from database using jsp
jsp
jsp  I Want complete note on JSP servlet
jsp
jsp  how to upload image through csv format in jsp
How to create a data base connectivity using sqlserver or Mydql through J2ME - JDBC
How to create a data base connectivity using sqlserver or Mydql through J2ME... connectivity using sqlserver through J2ME. Currently we are working... in either jsp or servlet , how to call the jsp class file in midlet(J2me app
JSP
What are JSP directives, page directives and include directives?  what are jsp directives? and what are page directives? and what are include directives? can you explain taglib directives?   JSP directives JSP
JSP
Can you explain jsp page life cycle what is el how does el search for an attribute in JSP  Can you explain jsp page life cycle what is el how does el...://www.roseindia.net/jsp/simple-jsp-example/LifeCycleOfJspPage.shtml http
JSP
JSP  what are the different scopes an object can have in a jsp page   JSP Scope Variables: Page scope-It makes the data available... the following links: http://www.roseindia.net/jsp/simple-jsp-example
us.fatehi - schemacrawler-sqlserver version 14.16.02 Maven dependency. How to use schemacrawler-sqlserver version 14.16.02 in pom.xml?
us.fatehi  - Version 14.16.02 of schemacrawler-sqlserver Maven dependency...-sqlserver in pom.xml? How to use schemacrawler-sqlserver version 14.16.02 in pom.xml... us.fatehi  - Version 14.16.02 of schemacrawler-sqlserver in project by the help
us.fatehi - schemacrawler-sqlserver version 16.2.2 Maven dependency. How to use schemacrawler-sqlserver version 16.2.2 in pom.xml?
us.fatehi  - Version 16.2.2 of schemacrawler-sqlserver Maven dependency? How to use  us.fatehi  - Version 16.2.2 of schemacrawler-sqlserver in pom.xml? How to use schemacrawler-sqlserver version 16.2.2 in pom.xml? Learn
jsp
jsp  how to connect the database with jsp using mysql   Hi Friend, Please visit the following links:ADS_TO_REPLACE_1 http://www.roseindia.net/jsp/connectjspwith_mysql.shtml http://www.roseindia.net/jsp
JSP
what is jstl in JSP   what is jstl   JSTL is also called as JSP tag libraries. They are collection of custom actions which canbe accessed as JSP tags. For more information, visit the following link: JSTL Tutorials
JSP
access application data stored in JavaBeans components. The jsp expression...). Before JSP 2.0, we could use only a scriptlet, JSP expression, or a custom tag to include server state in the jsp page output. For more information, visit
JSP
JSP public opinion poll   Develop a JSP for a news channel to conduct public opinion poll on any topic. Users will respond through yes or no options. Later display the result in percentage
jsp
jsp  hai please give me the table grid code code for jsp
jsp
jsp  how to create multiple tables in oracle 9i using jsp program

Ads