NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

GUIDs and databases

 
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users
View previous topic :: View next topic  
Author Message
jinwah50



Joined: 13 Nov 2008
Posts: 2

PostPosted: Thu Nov 13, 2008 12:41 pm    Post subject: GUIDs and databases Reply with quote

Hi,

I want to read/write a GUID from/to a SQL Server field of the type uniqueidentifer.

I am using a PreparedStatement which has various methods such as setInt, setString etc.

How to setGUID? and then subsequently when I read it back in how do I read it?

Thanks

Jin
Back to top
jinwah50



Joined: 13 Nov 2008
Posts: 2

PostPosted: Thu Nov 13, 2008 3:52 pm    Post subject: RE: GUIDs and databases Reply with quote

The solution was to simply use setString and getString.

I am using org.safehaus.uuid.UUID as my GUID field type.

So for the write:

preparedStatement.setString(1, myObject.getUid().toString());

and the read:

result.setUid(new UUID(resultSet.getString(1)));

Just in case anybody else ever searches for this question!

Thanks

Jin
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo