import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class TryInsert extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
PrintWriter pw = response.getWriter();
String connectionURL = "jdbc:mysql://localhost:3306/dbfinals";
Connection con=null;
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection(connectionURL, "root", "");
if(!con.isClosed())
{
pw.println("Successfully connected to " + "MySQL server using TCP/IP...");
con.close();
}
PreparedStatement ps = con.prepareStatement("INSERT INTO tblPic VALUES(?,?)");
File file = new File("C:/Users/Blenda/Pictures/1.jpg");
FileInputStream fs = new FileInputStream(file);
ps.setInt(1,1);
ps.setBinaryStream(2,fs,fs.available());
int i = ps.executeUpdate();
if(i!=0)
{
pw.println("image inserted successfully");
}
else
{
pw.println("problem in image insertion");
}
}
catch (Exception e)
{
System.out.println(e);
}
}
}
This is my code. But only a blank white page appears everytime I run TryInsert.java. How to fix this? Thank you.
The image is not inserted to the database. ;(

New Topic/Question
Reply



MultiQuote







|