Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Selecting uinqueidentifier in JDBC

Author  Topic 

pkesel
Starting Member

2 Posts

Posted - 2002-10-12 : 02:02:10
I'm using JDBC to access a SQL Server 2000 database and I need to select a uniqueidentifier from one table and insert its value into another. What Java type, or more matter of factly what ResultSet method, do I use to grab the identifier from the select statement? The notes on the JDBC driver I'm using says the value is a JDBC VARBINARY type.

Thanks,

-PK

ashok
Yak Posting Veteran

57 Posts

Posted - 2002-10-12 : 05:17:29
i remember suffering with a very similar problem. unfortunately microsoft stores the uniquedident. fields as a varbinary field in the database but it is returned in a formatted manner (with "-"s). the beta jdbc driver for mssql7 just couldnt handle uniqueidentifiers and did not implement a getString() method for the recordset.
Maybe you should try using getstring() ? (hoping the sql2k driver has implemented it...!). At that time i ended up using the driver from WebLogic, it didnt handle uids but supported getString().
worst case you can always try using getBytes() though...



-ashok
http://www.unganisha.org
Go to Top of Page

pkesel
Starting Member

2 Posts

Posted - 2002-10-12 : 12:25:47
Considering that you could insert uniqueidentifiers as a string, I searched around and found the CONVERT function and used it to select the column as a string.

select CONVERT(varchar(36),myGUID) from my_table

It worked like a charm. I could use the value returned to insert directly into another table as the foreign key I needed.

-PK
Go to Top of Page
   

- Advertisement -