Main   Products   Offshore Outsourcing   Customers   Partners   ContactUs  
JDBC Databases
  HXTT Access v5.2
  HXTT Cobol v2.1
  HXTT DBF v5.2
 
  Buy Now
  Support
  Download
  Document
  FAQ
  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 DBF
Changes by other programs are not see when prepared statements are cached
Rob Gansevles
2009-02-24 02:08:36.0
Hello,

We still have another issue, it seems when changes are made by another client and we are re-using prepared statements (for performance) we do not see the changes.

Sample programs:
1. start DBFTest3a, it creates a test table and sleeps some time
2. during the sleep, run DBFTest3b, it updates the table
after the sleep period the first program still sees the original value unless the prepared statement is closed first.

You may have to change the url to point to an empty directory.

Regards,

Rob

------ sample DBFTest3a -------
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
* Sample program that shows prepared statements cannot be cached (reused) when changes are made outside the jvm.
*
*/
public class DBFTest3a
{
private static final String SELECT_X_FROM_TST = "select x from tst";

public static void main(String[] args) throws Exception
{
String user = "";
String password = "";
String url = "jdbc:dbf:////tmp/dbftest";
String driver = "com.hxtt.sql.dbf.DBFDriver";

Class.forName(driver);

try
{
Connection connection = DriverManager.getConnection(url, user, password);
Statement statement = connection.createStatement();
statement.execute("drop table tst");
statement.close();
connection.close();
}
catch (SQLException e)
{
// table does not exists
}

boolean ok = true;
Connection connection = DriverManager.getConnection(url, user, password);
connection.setAutoCommit(true);

Statement statement = connection.createStatement();
statement.execute("create table tst (x integer)");
statement.close();

statement = connection.createStatement();
statement.executeUpdate("insert into tst (x) values (1)");
statement.close();

connection.close();

connection = DriverManager.getConnection(url, user, password);
connection.setAutoCommit(true);
connection.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);

PreparedStatement prepareStatement = null;
ResultSet rs;
prepareStatement = connection.prepareStatement(SELECT_X_FROM_TST);
rs = prepareStatement.executeQuery();
if (rs.next())
{
int x = rs.getInt("x");
if (x != 1)
{
System.out.println("** unexpected initial value, expected 1 retrieved " + x);
ok = false;
}
}
else
{
System.out.println("** missing record");
ok = false;
}
rs.close();
prepareStatement.clearParameters();

//when following line is uncommented it works!
//prepareStatement.close();

int sleep = 15;
System.out.println(" -- sleeping for " + sleep + " seconds, run \"update tst set x = 2\" in another jvm");
Thread.sleep(sleep * 1000);
System.out.println("select updated table");

prepareStatement = connection.prepareStatement(SELECT_X_FROM_TST);

rs = prepareStatement.executeQuery();
if (rs.next())
{
int x = rs.getInt("x");
if (x != 2)
{
System.out.println("** unexpected updated value, expected 2 retrieved " + x);
ok = false;
}
}
else
{
System.out.println("** missing record");
ok = false;
}
rs.close();

prepareStatement.close();
connection.close();

System.out.println(ok ? "OK" : "FAILED");
}
}


------ sample DBFTest3b -------

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

/**
* update test table
*
*/
public class DBFTest3b
{
private static final String UPDATE_TST_SET_X_2 = "update tst set x = 2";

public static void main(String[] args) throws Exception
{
String user = "";
String password = "";
String url = "jdbc:dbf:////tmp/dbftest";
String driver = "com.hxtt.sql.dbf.DBFDriver";

Class.forName(driver);

Connection connection = DriverManager.getConnection(url, user, password);
connection = DriverManager.getConnection(url, user, password);

Statement statement = connection.createStatement();
statement.executeUpdate(UPDATE_TST_SET_X_2);
statement.close();

connection.commit();

connection.close();

System.out.println("updated: " + UPDATE_TST_SET_X_2);
}

}
Re:Changes by other programs are not see when prepared statements are cached
HXTT Support
2009-02-24 02:47:56.0
>String url = "jdbc:dbf:////tmp/dbftest";
You should use lockType connection property, if you run different programs in different Java VM.
For instance, String url = "jdbc:dbf:////tmp/dbftest?lockType=VFP";
Re:Re:Changes by other programs are not see when prepared statements are cached
HXTT Support
2009-03-11 23:37:39.0
Please download the latest package.
# v4.2.052 fixed an insert bug on CDX index since v4.2.039.
# v4.2.040 supports EVALUATE(cExpression).
# v4.2.039 solved a CDX multiuser compatibility issue with VFP, which VFP will produce specific duplicated index information sometimes on mulituser mode.
# v4.2.038 fixed a bug on LEFT JOIN, which will return empty result for specific condition.
# v4.2.038 supports TYPE(cExpression) and VARTYPE(expression).
# v4.2.031 fixed a bug for DISTINCT operation, which missed the possible data row when there's deleted row with the same value.
# v4.2.013 fixed a bug on CDX compound format index file, which will sometimes set wrong index node information for specific complicated string index expression on insert operation.

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