hello everyone i want to know how i can store the image in my database(PostGreSql pgadmin iii) using jsp and glassfish as a server. i have the following code but it go to exception at pst.setBytes(2,b)....... thnx

con = getConnection();
String exsistingFileName= "C:\\temp\\myimage.gif"; 
File file = new File(exsistingFileName);
FileInputStream fis = new FileInputStream(file);
PreparedStatement ps = con.prepareStatement("INSERT INTO images VALUES (?, ?)");
ps.setString(1, file.getName());
byte[] b= new byte[fis.available()+1];
fis.read(b);
pst.setBytes(2,b);
int s = ps.executeUpdate();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.