File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Binary datatype in MS SQL via JDBC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Binary datatype in MS SQL via JDBC" Watch "Binary datatype in MS SQL via JDBC" New topic
Author

Binary datatype in MS SQL via JDBC

Muthukrishnan Manoharan
Ranch Hand

Joined: Aug 27, 2008
Posts: 91

Hi,
Can anyone help me how can i insert binary data into MS SQL through JDBC.

For example,
I created a table like

I couldnt find any method like setBinary() in PreparedStatement class..

Also here sample_id is the primary key. So I will have to create an auto-increment value for this. Will it be fine if I create it through DB or manually through Java.

Thanks,
Muthu

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38007
    
  22
You will have to create auto increment columns in the database, and don't attempt to set them from a client application. Don't even try to update the primary key.
By the way: Why are you using binary? In MySQL you usually use serial which is shorthand for "longint unique auto_increment not null" or similar.
Muthukrishnan Manoharan
Ranch Hand

Joined: Aug 27, 2008
Posts: 91

Okay..
But I am using Microsoft SQL Server. And in case I am using binary, I dont have an option for auto incrementing it (i.e. through IDENTITY function in Microsoft SQL Server) available for binary data. They are available only for integers.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Treat it like you would any binary data type, use setBytes() to set its content.

Using a binary value for a primary key is not a good idea, why have you chosen this data type? You can't auto increment it using SQL Server functionality, you'll have to do this yourself.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38007
    
  22
Oh, sorry, I misread the post, thinking MSSQL was MySQL. Sorry.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Binary datatype in MS SQL via JDBC
 
Similar Threads
Different versions of SQL Server
MS SQL JDBC driver download
Passing more than one parameter to the jasper report
Dynamic table creation based on excel template.
help needed for MS SQL Server