I'm querying an MS Access database and getting the following error:
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.
The relevant code:
private SimpleStringProperty getProduct(String bc) {
Connection conn;
String dbDriver;
Statement st;
ResultSet rs;
SimpleStringProperty prod = new SimpleStringProperty();
System.out.println("BC sent to db is: " + bc.toString());
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
dbDriver = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};"
+ "DBQ=Inventario.mdb;";
conn = DriverManager.getConnection(dbDriver, "", "");
st = conn.createStatement();
String getProduct = "SELECT * FROM Articulos "
+ "WHERE BarCode = " + bc; // .toString();
Where bc is a parameter obtained from a TextField box as a string, passed to this method as a string and the BarCode field in MS Access is of type Text.
As an aside, I am obviously working with a bar code, which is a number, but some of my bar codes have leading 0s, which is why I have it as text. Is there a way to work with bar codes of varying lengths and varying amounts of significant leading zeros as anything other than text/string? As you can see in my code, I even tried explicitly sending bc.toString() from JavaFX to MS Access, but I keep getting the data type mismatch error.
Final note: at various points I have placed System.out.println() to see what data is being passed, and at all points it appears correct. I have even taken out the criteria clause and just printed my result set, and all the proper data is coming back from Access.