DataBase:MS SQL Server
the Colume is image(image)
<java file>
================================================
import java.io.*;
import java.sql.*;
public class InsertBlob {
public static void main(String args[]) {
String username;
String password;
String url;
String dropString;
String createString;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
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");
try{
fis = new FileInputStream(file);
} catch(FileNotFoundException e) {}
PreparedStatement ps = con.prepareStatement("insert image (value) values (?)");
ps.setBinaryStream(1,fis,3098);
ps.executeUpdate();
ps.close();
try{
fis.close();
} catch(IOException e) {}
System.out.println ("Image Items have been inserted, you can now run the QueryCoffees program");
con.close();
}
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();
System.out.println("");
}
}
}
}
=================================================
Run:
get the message:
'SQLState:22001'
'ErrorCode:8152'
'SQLState:01000'
'ErrorCode:3621'
[ October 21, 2002: Message edited by: Jewel Young ]
the Colume is image(image)
<java file>
================================================
import java.io.*;
import java.sql.*;
public class InsertBlob {
public static void main(String args[]) {
String username;
String password;
String url;
String dropString;
String createString;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
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");
try{
fis = new FileInputStream(file);
} catch(FileNotFoundException e) {}
PreparedStatement ps = con.prepareStatement("insert image (value) values (?)");
ps.setBinaryStream(1,fis,3098);
ps.executeUpdate();
ps.close();
try{
fis.close();
} catch(IOException e) {}
System.out.println ("Image Items have been inserted, you can now run the QueryCoffees program");
con.close();
}
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();
System.out.println("");
}
}
}
}
=================================================
Run:
get the message:
'SQLState:22001'
'ErrorCode:8152'
'SQLState:01000'
'ErrorCode:3621'
[ October 21, 2002: Message edited by: Jewel Young ]