File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Binary datatype in MS SQL via JDBC

 
Muthukrishnan Manoharan
Ranch Hand
Posts: 91
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47229
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 91
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47229
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, sorry, I misread the post, thinking MSSQL was MySQL. Sorry.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic