这是我previous question about using multivalue in UCanAccess的延续。我相信我已按照the ComplexTest.java example中的设置设置了我的查询,并且我已经修复了&按suggested in another stackoverflow answer压缩我的Access数据库。 我能够使用getObject正确选择多值字段,但是当我在带有WHERE子句的PreparedStatement中的问号上使用带有SingleValue或SingleValue []的setObject时,返回的结果集不会反映WHERE的限制。而不是返回几百条记录,它返回完整的表或表的组合。 有人有建议吗? 这是我的代码:
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import net.ucanaccess.complex.SingleValue;
public class WhereQuery {
public static void main(String[] args) {
String sql = "SELECT [A-CCBC-BaseDrawings-1].* FROM [TableA] WHERE ((([TableA].Place)=?));";
File database = new File("/Users/George/Java/WhereQueryProject/Database.accdb"); // Access database
Connection conn = null; // The connection object
try {
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver"); // Sets up the UCanAccess driver
conn = DriverManager.getConnection("jdbc:ucanaccess://"+database.getPath()); // connects to the MS Access database
}
catch (ClassNotFoundException cnfe) {
cnfe.printStackTrace();
}
catch (SQLException se) {
se.printStackTrace();
}
PreparedStatement ps = null;
ResultSet rs = null;
try {
ps = conn.prepareStatement(sql);
ps.setObject(1,new SingleValue[]{new SingleValue("Baltimore")});
rs = ps.executeQuery();
}
catch (SQLException e) {
e.printStackTrace();
}
FromAccess.printResultSet(rs, sql); // a method for printing result sets
}
}