3

So I am coding in Java, using JDBC with SQL to get data from a database. I cannot chnage the data or the column names in the database. Everything worked perfectly until I was told today that another column of the database was needed.

So I tried to add the column name to the select statement, however I get an error:

"java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 2."

Here is the variable and name for the column: String est = "\"Estimates Complete?\"";

So after LOTS of research, it seems that there is something called "Bind Variables" in JDBC and ? happens to be one of them. I keep finding forum posts and answers on how to create Bind Variables, but nothing on how to "Escape" them. I cannot change the value of the Estimates Complete? column, and it is needed for my program.

If I try String est = "Estimates Complete?";, then the error I get is:

java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]COUNT field incorrect

Anyone know if it is possible? Thanks.

Edit: Code example:

Statement s = conn.createStatement();
String tableName = "\"Open WRs V2\"", data1 = "\"Project Name\"",est = "Estimates Complete?";
String selTable = "SELECT " + data1  + "," + est+ " FROM " + tableName;
s.execute(selTable);
ResultSet rs = s.getResultSet();
while ((rs.next())) {
    String name = (rs.getString(1));
    String estimate= rs.getString(2);
    System.out.println("test: "+estmate);
}
s.close();
Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
  • Have you tried using brackets `[]`? – Luiggi Mendoza Jul 17 '13 at 20:20
  • 2
    Could you show an example of your SQL? – Jon Skeet Jul 17 '13 at 20:20
  • I added code. Forgive how badly formatted it looks. I still haven't completed figured out this site. – Programming Cat Jul 17 '13 at 20:27
  • @Luiggi, I'm not sure what you mean by adding brackets, but I tried: String est = "\"Estimates Complete[?]\""; and it gave: java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in query expression '[Estimates Complete[Pa_RaM000]]'. Then I tried String est = "\"[Estimates Complete?]\""; and it gave: java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in query expression '[[Estimates CompletePa_RaM000]]'. – Programming Cat Jul 17 '13 at 20:30

1 Answers1

0

can you replace the ? with chr(63) like in the answer here :

How to avoid ODBC parameterization for the question mark character ? within literals and comments?

Community
  • 1
  • 1
Graham Griffiths
  • 2,196
  • 1
  • 12
  • 15