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
Error dropping table after selecting on it from another connection
Rob Gansevles
2012-06-26 13:20:13.0
Hi,

I get an error when I want to drop a table that has been queried from another connection.
See sample java code below.

How can I drop the table?

Thanks,
Rob Gansevles

public static void main(String[] args) throws Exception
{
Class.forName("com.hxtt.sql.dbf.DBFDriver");
String url = "jdbc:dbf:////tmp/test_hxtt_dbf?lockType=VFP";

java.util.Properties info = new java.util.Properties();
info.setProperty("delayedClose", "0"); // does not make a difference

java.sql.Connection connection1 = java.sql.DriverManager.getConnection(url, info);
java.sql.Connection connection2 = java.sql.DriverManager.getConnection(url, info);

java.sql.PreparedStatement ps = null;
try
{
ps = connection1.prepareStatement("drop table tst");
ps.execute();
}
catch (Exception e) { }
finally
{
if (ps != null) ps.close();
}

ps = connection1.prepareStatement("create table tst (x integer)");
ps.execute();
ps.close();

java.sql.Statement stat = connection1.createStatement();
java.sql.ResultSet rs = stat.executeQuery("select x from tst");
rs.next();
rs.close();
stat.close();

ps = connection2.prepareStatement("drop table tst");
ps.execute();
ps.close();

connection1.close();
connection2.close();
}
Re:Error dropping table after selecting on it from another connection
HXTT Support
2012-06-26 19:31:08.0
Supported. Please download the latest package.
Re:Re:Error dropping table after selecting on it from another connection
Rob Gansevles
2012-06-27 05:05:05.0
Hi,thanks for the quick fix.

The example now works, but in our system we need to use transaction level TRANSACTION_READ_COMMITTED.
When I create the connections as shown below I still get the same exception.

Thanks in advance
Rob

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

java.util.Properties info = new java.util.Properties();

java.sql.Connection connection1 = java.sql.DriverManager.getConnection(url, info);
if (connection1.getMetaData().supportsTransactionIsolationLevel(Connection.TRANSACTION_READ_COMMITTED))
{
connection1.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
}
java.sql.Connection connection2 = java.sql.DriverManager.getConnection(url, info);
if (connection2.getMetaData().supportsTransactionIsolationLevel(Connection.TRANSACTION_READ_COMMITTED))
{
connection2.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
}
Re:Re:Re:Error dropping table after selecting on it from another connection
HXTT Support
2012-06-27 06:03:49.0
Please download the latest package agian.

For older packge, you can add
connection1.commit();
Re:Re:Re:Re:Error dropping table after selecting on it from another connection
Rob Gansevles
2012-06-27 12:34:57.0
Hi,

It works now for select, but after an insert I still get the same exception, see sample code below.

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 connection1 = java.sql.DriverManager.getConnection(url, new java.util.Properties());
if (connection1.getMetaData().supportsTransactionIsolationLevel(java.sql.Connection.TRANSACTION_READ_COMMITTED))
{
connection1.setTransactionIsolation(java.sql.Connection.TRANSACTION_READ_COMMITTED);
}

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

java.sql.PreparedStatement ps = null;
try
{
ps = connection1.prepareStatement("drop table tst");
ps.execute();
}
catch (Exception e) { }
finally { if (ps != null) ps.close(); }

ps = connection1.prepareStatement("create table tst (x integer)");
ps.execute();
ps.close();

ps = connection1.prepareStatement("insert into tst (x) values (?)");
ps.setInt(1, 99);
ps.executeUpdate();
ps.close();

ps = connection2.prepareStatement("drop table tst");
ps.execute();
ps.close();

connection1.close();
connection2.close();
Re:Re:Re:Re:Re:Error dropping table after selecting on it from another connection
HXTT Support
2012-06-27 16:49:55.0
>It works now for select, but after an insert I still get the same exception, see sample code below.
Yeah. It's impossible to drop that table because you haven't commit/rollabck your insert data.

ps = connection1.prepareStatement("insert into tst (x) values (?)");
ps.setInt(1, 99);
ps.executeUpdate();
ps.close();

You need to add connection1.commit() here.
Re:Re:Re:Re:Re:Re:Error dropping table after selecting on it from another connection
HXTT Support
2012-06-28 00:00:44.0
Checked and fixed. An autocomit mode needn't to call connection1.commit() .
Re:Re:Re:Re:Re:Re:Re:Error dropping table after selecting on it from another connection
Rob Gansevles
2012-07-03 00:07:13.0
Hi,

Thanks for all the quick fixes, it works now in regular cases.
But, when I use the prepared statements in a pool I still get the same error.
Turning off prepared statement pooling is possible but has an impact on performance.

The code below simulates prepared statement pooling by closing the prepared statement only when the connection is closed.

Is it possible to handle this case as well?

Thanks in advance.
Rob Gansevles

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

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

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

java.sql.PreparedStatement ps = null;
try
{
ps = connection1.prepareStatement("drop table tst");
ps.execute();
}
catch (Exception e)
{
}
finally
{
if (ps != null) ps.close();
}

ps = connection1.prepareStatement("create table tst (x integer)");
ps.execute();
ps.close();

java.sql.PreparedStatement insert = connection1.prepareStatement("insert into tst (x) values (?)");
insert.setInt(1, 99);
insert.executeUpdate();
// insert.close(); // simulate prepared statement pool

java.sql.PreparedStatement drop = connection2.prepareStatement("drop table tst");
drop.execute();
// drop.close(); // simulate prepared statement pool

insert.close(); // simulate prepared statement pool
connection1.close();
drop.close(); // simulate prepared statement pool
connection2.close();
Re:Re:Re:Re:Re:Re:Re:Re:Error dropping table after selecting on it from another connection
HXTT Support
2012-07-03 00:35:52.0
>The code below simulates prepared statement pooling by closing the prepared statement only when the connection is closed.
>Is it possible to handle this case as well?
// insert.close(); // simulate prepared statement pool
No way. You need to call insert.close(); A PreparedStatement is using a table, so that you can't drop that table.

>Turning off prepared statement pooling is possible but has an impact on performance.
Don't worry. All issues in this thread are resulted by the new sql pool, which supports for not only PreparedStatement, but also random common sql of Statement.

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