The Artima Developer Community
Sponsored Link

Java Answers Forum
Adding a binary file to the BLOB column through command line in MSSQL

1 reply on 1 page. Most recent reply: Nov 7, 2008 11:06 AM by aeri form

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
srinivas gandrath

Posts: 1
Nickname: sree5782
Registered: Oct, 2008

Adding a binary file to the BLOB column through command line in MSSQL Posted: Oct 27, 2008 9:24 AM
Reply to this message Reply
Advertisement
Hi All,

Does SQL Server provides a utility for us to run on the command line to add a binary file to the blob column via a sql statement or stored procedure call.

Thanks in Advance.

Regards
Srinivas


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
Reply to this message Reply
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
}

Flat View: This topic has 1 reply on 1 page
Topic: Method help Previous Topic   Next Topic Topic: another beginners question in java

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use