I am evaluating the driver and came across a curious issue. I execure query using PreparedStatement. Where clause has something like 'date_column BETWEEN ? AND ?' If I enter September 4, 1992 as the first parameter, no records are returned, while September 5, 1992 return records properly. BTW, all records in that column/field are dated between 1994 and 2004. Do you have any idea why it's happening? Thanks!
|
Hello!!! Anybody!? Any ideas??
|
Sorry for omitting that thread. Failed to recur. Maybe that's an index issue. You can run once "reindex all on thattable", then your issue maybe disappear. I test your issue by the following code.
package test.jdbc.dbf;
import java.net.URL;
import java.sql.*;
import java.util.Properties;
public class testPrepBetween {
public static void main(String argv[]) {
try {
Class.forName("com.hxtt.sql.dbf.DBFDriver").newInstance();
String dir = "/dbffiles"; //Change it to yourdbfdir
String url;
if (argv.length < 1)
url = "jdbc:DBF:///" + dir;
else
url = argv[0];
Properties properties = new Properties();
// properties.put("charSet", "Cp860");
Connection con = DriverManager.getConnection(url, properties);
PreparedStatement pstmt;
ResultSet rs;
String colval;
String temp;
ResultSetMetaData resultSetMetaData;
int iNumCols;
String sql;
sql =
"SELECT int1,date1 FROM test WHERE date1 between ? and ? ";
pstmt = con.prepareStatement(sql);
resultSetMetaData = pstmt.getMetaData();
iNumCols = resultSetMetaData.getColumnCount();
for (int j = 1; j <= iNumCols; j++)
System.out.print(resultSetMetaData.getColumnLabel(j) + " ");
System.out.println();
pstmt.setDate(1, new java.sql.Date(92,3,4));
pstmt.setDate(2,new java.sql.Date(System.currentTimeMillis()));
rs = pstmt.executeQuery();
while (rs.next()) {
for (int j = 1; j <= iNumCols; j++) {
colval = rs.getObject(j) + "";
System.out.print(colval + " ");
}
System.out.println();
}
rs.close();
pstmt.close();
con.close();
}
catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
}
}
|