Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JDBC jsp with sqlserver
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


dollyg
jsp with sqlserver
2 Answer(s)      6 years and 3 months ago
Posted in : JDBC



Advertisement
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
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
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
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
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
Sending form data from HTML page to SQLserver 2005 database by calling servlet code
Sending form data from HTML page to SQLserver 2005 database by calling servlet code  Hi sir, I would like to know how to send the form data from html page to database by calling servlet code from html page .   
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
jsp
jsp  how to include two jsp page
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  Can I implement interface in jsp
jsp
jsp  how to create jsp page
JSP
JSP  How to run jsp program in eclipse
jsp
jsp  how jsp translated into servlets
online database connectivity issue from JSP page .
online database connectivity issue from JSP page .  Hi; Everything... = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;"+"databaseName...("com.microsoft.sqlserver.jdbc.SQLServerDriver"); conn = DriverManager.getConnection("jdbc:sqlserver
online database connectivity issue from JSP page .
online database connectivity issue from JSP page .  Hi... = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;"+"databaseName=dorakoina...("com.microsoft.sqlserver.jdbc.SQLServerDriver"); conn = DriverManager.getConnection("jdbc:sqlserver
online database connectivity issue from JSP page .
online database connectivity issue from JSP page .  Hi... = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;"+"databaseName=dorakoina...("com.microsoft.sqlserver.jdbc.SQLServerDriver"); conn = DriverManager.getConnection("jdbc:sqlserver
jsp
jsp  write a code for jsp file generator to generate a jsp page automatically taking html page as input
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  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
jsp
jsp  how to connect the database with jsp using mysql   Hi Friend, Please visit the following links: http://www.roseindia.net/jsp/connectjspwith_mysql.shtml http://www.roseindia.net/jsp/Accessingdatabase-fromJSP.shtml
jsp
jsp  how to upload image through csv format in jsp
jsp
jsp  I Want complete note on JSP servlet
jsp
jsp  how to delete data from database using jsp
JSP
JSP  FILE UPLOAD-DOWNLOAD code USING JSP
jsp
jsp  how to write hindi in jsp and store in database as unicode
jsp
jsp  code for jsp automatic genration using html
jsp
jsp  why jsp is translated into servlet?pls describe precisly
 

 

 

DMCA.com