This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can I put the image into the DataBase?

Jewel Young
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DataBase:MS SQL Server
the Colume is image(image)
<java file>
import java.sql.*;
public class InsertBlob {
public static void main(String args[]) {
String username;
String password;
String url;
String dropString;
String createString;

try {
}catch(java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
try {
Connection con;
Statement stmt;
con =java.sql.DriverManager.getConnection("jdbc dbc:TryDataBase");
System.out.println ("Ok, connection to the DB worked. Let's see if we can insert something:");
FileInputStream fis=null;
File file = new File("eat.gif");

fis = new FileInputStream(file);
} catch(FileNotFoundException e) {}

PreparedStatement ps = con.prepareStatement("insert image (value) values (?)");
} catch(IOException e) {}
System.out.println ("Image Items have been inserted, you can now run the QueryCoffees program");
catch(SQLException ex) {
System.err.println("==> SQLException: ");
while (ex != null) {
System.out.println("Message: " + ex.getMessage ());
System.out.println("SQLState: " + ex.getSQLState ());
System.out.println("ErrorCode: " + ex.getErrorCode ());
ex = ex.getNextException();
get the message:
[ October 21, 2002: Message edited by: Jewel Young ]
prabhat kumar
Ranch Hand
Posts: 114
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am not sure abt sql server, but in oracle
it works olny when you
do these two things:
1. first set the dbCon.setautocommit() to false
2. then insert the blob using emptyblob() function and then set the binary stream.
at least try the first thing and see
I agree. Here's the link:
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic