Hi,
My Requirement is to upload the images into database through jsp. For that i write a code .And it works fine .But in that File imgfile = new File("C:/Program Files/Apache Software Foundation/Tomcat 5.5/webapps/test/Blue.jpg"); instead of that i used File imgfile = new File("Blue.jpg" ); like that it didn't work. When we browse that image from local system it automatically takes like Blue.jpg and didn't take the full path.
So i got the error as " Blue.jpg not found". Please tell the solution how can i resolve my problem.
My Requirement is to upload the images into database through jsp. For that i write a code .And it works fine .But in that File imgfile = new File("C:/Program Files/Apache Software Foundation/Tomcat 5.5/webapps/test/Blue.jpg"); instead of that i used File imgfile = new File("Blue.jpg" ); like that it didn't work. When we browse that image from local system it automatically takes like Blue.jpg and didn't take the full path.
So i got the error as " Blue.jpg not found". Please tell the solution how can i resolve my problem.
Code:
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*"%>
<%
String connectionURL = "jdbc:mysql://localhost:3306/";
String dbName = "user_register";
Connection connection = null;
PreparedStatement pre=null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection(connectionURL+dbName, "root", "root");
out.println("connection");
File imgfile = new File("C:/Program Files/Apache Software Foundation/Tomcat 5.5/webapps/test/Blue.jpg");
out.println("reerr");
FileInputStream fin = new FileInputStream(imgfile);
pre = connection.prepareStatement("insert into Image values(?,?,?)");
pre.setInt(1,3);
pre.setString(2,"new");
pre.setBinaryStream(3,fin,(int)imgfile.length());
pre.executeUpdate();
out.println("Inserting Successfully!");
%>
Comment