Main   Products   Offshore Outsourcing   Customers   Partners   ContactUs  
JDBC Databases
  HXTT Access v5.2
 
  Buy Now
  Support
  Download
  Document
  FAQ
  HXTT Cobol v2.1
  HXTT DBF v5.2
  HXTT Excel v4.2
  HXTT Paradox v5.2
  HXTT Text(CSV) v5.2
  HXTT XML v1.2
Offshore Outsourcing
Oracle Data Import/Export
DB2 Data Import/Export
Sybase Data Import/Export
Free Resources
  Firewall Tunneling
  Search Indexing Robot
  Conditional Compilation
  Password Recovery for MS Access
  Password Recovery for Corel Paradox
  Checksum Tool for MD5
  Character Set Converter
  Pyramid - Poker of ZYH
   
   
   
Hongxin Technology & Trade Ltd. of Xiangtan City (abbr, HXTT)

HXTT ACCESS
GUID in Access Database (print it out)
Jeff Hill
2016-07-12 11:39:52.0
Hello! We have successfully used your driver in the past for project and we have a new project where we need to get a new license and take a GUID (replication id) from an access database and print it out to another text file the same way it looks in access. Before purchasing, I was trying to do this with the demo download and I was able to get a 16 element byte array, but the values do not seem to match with the GUID in access.

I have looked online at this post and I also get a byte array of length 16, but I can not get the same GUID to print out in java as is displayed in the access database. (Example print outs below)
http://www.hxtt.com/support/access1365714000.html

http://www.hxtt.com/support_view_issue.jsp?product=access&id=1176808563


The GUID in the access database looks like this...
{2E850009-6FA5-4B6B-BEAE-3C405B51B1F5}

When I do a simple query from the access database with the HXTT driver - I get these bytes...
9,0,-123,46,-91,111,107,75,-66,-82,60,64,91,81,-79,-11

How should I translate/convert those bytes to print out the human-readable GUID like 2E850009-6FA5-4B6B-BEAE-3C405B51B1F5


========================================
EXAMPLE CODE
========================================

I created a sample database for testing with one table.
Database2.mdb
Table name = Table1
Column1=ID, Replication ID, Indexed Yes(No Duplicates)
Column2=displayCode, ShortText

I modified the "example1" code from the demo download to try out several ways of reading the GUID, but none are working currently...



import java.io.File;
import java.sql.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.UUID;

/* A demo show how to use Statement.executeQuery(sql). */
public class Example1 {
public static void main(String argv[]) {
try {
Class.forName("com.hxtt.sql.access.AccessDriver").newInstance();

//Please see Connecting to the Database section of Chapter 2. Installation in Development Document
//Please change "demodata" to your database directory


File mdbFile=new File("Database2.mdb");


String url = "jdbc:Access:///"+mdbFile.getAbsolutePath();

//Please replace with your query statement.
//You should read SQL syntax in HXTT Access Development Document
// String sql = "select * from test where number1>0";
String sql="select * from table1 order by displayCode limit 1 ";

Connection con = DriverManager.getConnection(url, "", "");

Statement stmt = con.createStatement();
stmt.setFetchSize(10);

ResultSet rs = stmt.executeQuery(sql);

ResultSetMetaData resultSetMetaData = rs.getMetaData();
int iNumCols = resultSetMetaData.getColumnCount();
for (int i = 1; i <= iNumCols; i++) {
System.out.println(resultSetMetaData.getColumnLabel(i)
+ " " +
resultSetMetaData.getColumnTypeName(i));
}

Object colval;
while (rs.next()) {
for (int i = 1; i <= iNumCols; i++) {

if(i==1)
{
colval=rs.getBytes(i);



byte[] bytes=(byte[]) colval;


for(byte b:bytes)
{
System.out.print(b+",");
}

System.out.println();

System.out.println("Byte Array Length="+bytes.length);
System.out.print("Byte to String="+new String(bytes));



byte[] newByte={bytes[3],bytes[2],bytes[1],bytes[0],bytes[5],bytes[4],bytes[7],bytes[6],bytes[9],bytes[8],bytes[15],bytes[14],bytes[13],bytes[12],bytes[11],bytes[10]};


UUID uuid=UUID.nameUUIDFromBytes(bytes);
System.out.print(" Java UUID="+uuid.toString());
UUID uuid2=UUID.nameUUIDFromBytes(newByte);
System.out.print(" Java UUID2="+uuid2.toString());

}
else
{
colval = rs.getObject(i);
}
System.out.print(" Object Value="+colval);
}
System.out.println();
}

rs.close();
stmt.close();
con.close();
}
catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
}
}


========================================
OUTPUT
========================================
ID GUID AUTO_INCREMENT
displaycode VARCHAR
9,0,-123,46,-91,111,107,75,-66,-82,60,64,91,81,-79,-11,
Byte Array Length=16
Byte to String=




Re:GUID in Access Database (print it out)
HXTT Support
2016-07-12 16:47:51.0
Please use the following code:)

byte[] newByte = {bytes[3], bytes[2], bytes[1], bytes[0], bytes[5], bytes[4], bytes[7], bytes[6], bytes[8], bytes[9], bytes[10], bytes[11], bytes[12], bytes[13], bytes[14], bytes[15]};
StringBuffer strbuf=new StringBuffer();
for (int j = 0; j < newByte.length; j++) {
byte b = newByte[j];
if (j == 4 || j == 6 || j == 8 || j == 10) {
strbuf.append("-");
}
strbuf.append(Integer.toHexString(b & 0xFF).toUpperCase());
}

System.out.println(strbuf);

// UUID uuid2 = UUID.nameUUIDFromBytes(newByte);
UUID uuid2 = UUID.fromString(strbuf.toString());



System.out.println(" Java UUID2=" + uuid2.toString().toUpperCase());
Re:Re:GUID in Access Database (print it out)
HXTT Support
2016-09-05 22:14:02.0
2016-09-06 provides java.uti.UUID value for GUID type.

Now you should use rs.getObject(i) which will return java.util.UUID object.
rs.getString(i) will return a string value too.

Search Key   Search by Last 50 Questions




Google
 

Address: 9 Station Rd., Xiangtan City, Hunan Province, P.R. China
Postcode: 411100
Phone: (86)731-58225727
Fax: (86)731-58225727
Email: webmaster@hxtt.com
Copyright © 1999-2011 Hongxin Technology & Trade Ltd. | All Rights Reserved. | Privacy | Legal | Sitemap