aeri form
Posts: 1
Nickname: aeriform
Registered: Nov, 2008
|
|
Re: Adding a binary file to the BLOB column through command line in MSSQL
|
Posted: Nov 7, 2008 11:06 AM
|
|
Normally you'll want communicate with a database using a JDBC driver. I'd recommend the JTDS driver found at http://jtds.sourceforge.net/index.html which handles blob data. I have been using a version of this for several years without problems.
Using JTDS you can add blob data by using a FileInputStream such as:
FileInputStream fis = new FileInputStream(new File("blobData.binary")); java.sql.Connection connection = java.sql.DriverManager.getConnection("sqlServerURL", username, password);
try{
String nativeQuery = "INSERT INTO tableName(columnName) VALUES(?)"; PreparedStatement ps = connection.prepareStatement(nativeQuery); ps.setBinaryStream(1, fis, fis.available());
if(!ps.execute() && ps.getUpdateCount()==-1) throw new SQLException();
}catch(SQLException){ //do something here }
|
|