Here is an example for How to store image into database and retrive that and display one by one
steps
*****
1. create one temp folder under root
2. save this 3 files into that
3. create database in ms-sql server
4. note : if connection not establishing with this driver , better to use jdbc :-> Odbc :-> driver
5. database code for ms-sqlserver
-create table image (uid numeric(6) identity (1001,1), img image )
-select * from image
getfile.html
************
Gettostore.jsp
**************
<%@ page language=”java” import=”java.sql.*,java.io.*” errorPage=”" %>
<%
try
{
Connection con = null;
System.setProperty( “jdbc.drivers”, “com.microsoft.jdbc.sqlserver.SQLServerDriver” );
Class.forName( “com.microsoft.jdbc.sqlserver.SQLServerDriver” );
con = DriverManager.getConnection( “jdbc:microsoft:sqlserver://SCALAR6:1433;DatabaseName=JAVATEAM;SelectMethod=cursor;User=sa;Password=ontrack20″ );
PreparedStatement pst = con.prepareStatement(”insert into image(img) values(?)”);
//logo path is a value which is come from file browser
FileInputStream fis=new FileInputStream(request.getParameter ( “path” ) );
byte[] b= new byte[fis.available()+1];
fis.read(b);
pst.setBytes(1,b);
pst.executeUpdate();
pst.close();
con.close();
}
catch(SQLException e)
{
out.println ( e);
}
catch (ClassNotFoundException e)
{
out.println( e );
}
%>
link –>
Puttoview.jsp
*************
<%@ page contentType=”text/html; charset=iso-8859-1″ language=”java” import=”java.io.*,java.sql.*” errorPage=”" %>
Home
<%
try
{
Connection con = null;
System.setProperty( “jdbc.drivers”, “com.microsoft.jdbc.sqlserver.SQLServerDriver” );
Class.forName( “com.microsoft.jdbc.sqlserver.SQLServerDriver” );
con = DriverManager.getConnection( “jdbc:microsoft:sqlserver://SCALAR6:1433;DatabaseName=JAVATEAM;SelectMethod=cursor;User=sa;Password=ontrack20″ );
PreparedStatement pst = null;
ResultSet rs=null;
FileOutputStream fos;
int i = 0;
%>
.jpg” mce_src=”./image<%=i%>.jpg” >
<%=i%> |
//run : http://localhost:8080/temp/getfile.html