Ok, I have no hair left. When passing a constant string to executeQuery there's no problem. When passing a String object it fails and the exception is ' incorrect syntax near "."'
.
Everything is essentially exactly the same, but for some reason one case works and the other does not. To give a little background, I am connecting to an SQLServer2008 DB. What gives?
Here's the code that has taken my hair from me:
public List<IdValuePair> Get_Job_Types() {
ArrayList<IdValuePair> jt = Get_Id_Value_Pairs(
"SELECT * FROM USER_JOB_TYPE", "JOB_TYPE_ID", "JOB_TYPE");
return (jt);
}
private List<IdValuePair> Get_Id_Value_Pairs(String query, String idRowName,
String valueRowName) {
try {
List<IdValuePair> pairs = new ArrayList<IdValuePair>();
Class.forName("net.sourceforge.jtds.jdbc.Driver");
m_Connection = DriverManager.getConnection(db_connect_string,
db_userid, db_password);
Statement stmt = m_Connection.createStatement();
// THIS WORKS ?!
ResultSet rs = stmt.executeQuery("SELECT * FROM USER_JOB_TYPE");
// THIS DOESN'T !!!!???
rs = stmt.executeQuery(query);
// ...
rs.close();
stmt.close();
return (pairs);
}
catch (Exception e) {
e.printStackTrace();
return (null);
}
}