0

i want to upload pictures in a folder rather then Mysql database ,please give me direction to uploading images in a folder

3
Contributors
2
Replies
5
Views
7 Years
Discussion Span
Last Post by fredrickme
1

i want to upload pictures in a folder rather then Mysql database ,please give me direction to uploading images in a folder

import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class JdbcInsertImage extends  HttpServlet{
public void doGet(HttpServletRequest request, 
HttpServletResponse response) throws ServletException, IOException
{
PrintWriter pw = response.getWriter();
String connectionURL = "jdbc:mysql://localhost:3306/roseindia";
java.sql.Connection connection=null;
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection(connectionURL, 
"root", "root");
PreparedStatement pst = connection.prepareStatement
("insert into image values(?,?)");
File file = new File("C:/apache-tomcat-5.5.20/webapps
/mywork/grad_sm.gif");
FileInputStream fis = new FileInputStream(file);
pst.setBinaryStream(1,fis,fis.available());
pst.setString(2, "Tim");
int i = pst.executeUpdate();
if(i!=0)
{
pw.println("image has been inserted");
}
else
{
pw.println("image is not inserted");
}	
}
catch (Exception e)
{
System.out.println(e);
}
}
}

Edited by peter_budo: Keep it Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.