Main   Products   Offshore Outsourcing   Customers   Partners   ContactUs  
JDBC Databases
  HXTT Access v7.1
  HXTT Cobol v5.0
  HXTT DBF v7.1
 
  Buy Now
  Support
  Download
  Document
  FAQ
  HXTT Excel v6.1
  HXTT Paradox v7.1
  HXTT PDF v2.0
  HXTT Text(CSV) v7.1
  HXTT Word v1.1
  HXTT XML v4.0
Offshore Outsourcing
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
   
   
   
Heng Xing Tian Tai Lab of Xi'an City (abbr, HXTT)

HXTT DBF
statement.getGeneratedKeys() returns wrong value
Rob Gansevles
2012-07-09 08:15:08.0
Hi,

When I use the statement.getGeneratedKeys() feature I seem to get a value that is 1 too high, see code sample below.

My output is:
first key 2
second key 3
Actual key 1
Actual key 2

Regards,

Rob Gansevles

Class.forName("com.hxtt.sql.dbf.DBFDriver");
String url = "jdbc:dbf:////tmp/test_hxtt_dbf?lockType=VFP;delayedClose=0";

java.sql.Connection connection = java.sql.DriverManager.getConnection(url, new java.util.Properties());
if (connection.getMetaData().supportsTransactionIsolationLevel(java.sql.Connection.TRANSACTION_READ_COMMITTED))
{
connection.setTransactionIsolation(java.sql.Connection.TRANSACTION_READ_COMMITTED);
}

java.sql.PreparedStatement ps = connection.prepareStatement("drop table if exists tst");
ps.execute();
ps.close();

ps = connection.prepareStatement("create table tst (id integer not null auto_increment, val integer default null, primary key (id))");
ps.execute();
ps.close();

ps = connection.prepareStatement("insert into tst (val) values (8)", java.sql.Statement.RETURN_GENERATED_KEYS);
ps.executeUpdate();
java.sql.ResultSet rs = ps.getGeneratedKeys();
rs.next();
System.out.println("first key " + rs.getInt(1));
ps.close();

ps = connection.prepareStatement("insert into tst (val) values (10)", java.sql.Statement.RETURN_GENERATED_KEYS);
ps.executeUpdate();
rs = ps.getGeneratedKeys();
rs.next();
System.out.println("second key " + rs.getInt(1));
ps.close();

java.sql.Statement stat = connection.createStatement();
rs = stat.executeQuery("select id from tst");
while (rs.next())
{
System.out.println("Actual key " + rs.getInt(1));
}
rs.close();
stat.close();

connection.commit();
connection.close();
Re:statement.getGeneratedKeys() returns wrong value
HXTT Support
2012-07-09 21:33:43.0
Thanks. Fixed.

Search Key   Search by Last 50 Questions




Google
 

Email: webmaster@hxtt.com
Copyright © 2003-2019 Heng Xing Tian Tai Lab of Xi'an City. | All Rights Reserved. | Privacy | Legal | Sitemap