• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with SQL syntax.

 
Craig Snowbarger
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a list with a selection listener that is supposed to get the value of a selected item, pass it to a query and return a result set, but I'm getting an error: java.sql.SQLException:
"[Microsoft][ODBC Microsoft Access Driver] Syntax error in FROM clause."
Here's the code I'm using. HELP!
private void eListValueChanged(javax.swing.event.ListSelectionEvent evt) {
try {
Statement statement = dbconn.createStatement();
String query = "SELECT Make FROM Equipment" + "WHERE TestSetID =" + list.getSelectedValue();
info.setText( "\nQuerying Database" );
ResultSet rs = statement.executeQuery( query );
//display( rs );
String s = rs.getString("Make");
tMake.setText(s);
info.setText( "\nQuery Successful\n" );
statement.close();
}
catch ( SQLException sqlex ) {
sqlex.printStackTrace();
}
}
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you need a space between the word "equipment" and the word "where".
------------------
Moderator of the JDBC Forum
[This message has been edited by Thomas Paul (edited March 13, 2001).]
 
Craig Snowbarger
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So would I do that like this?
String query = "SELECT Make FROM Equipment" + " " + "WHERE TestSetID =" + list.getSelectedValue();
 
Craig Snowbarger
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adding the space in there returned an error of "too few parameters", so I tried this (code below) and I get an error that says I can't convert an object to a string. What gives, man?
String value = new String();
value = list.getSelectedValue();
Statement statement = dbconn.createStatement();
String query = "SELECT Make FROM Equipment" + " " + "WHERE TestSetID ='" + value + "'";
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JList.getSelectedValue() returns an Object, not a String. If it really is a String, cast it.
String value = (String)(list.getSelectedValue());
Statement statement = dbconn.createStatement();
String query = "SELECT Make FROM Equipment WHERE TestSetID ='" + value + "'";
 
Craig Snowbarger
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did that and now I'm getting an error that reads,

"java.sql.SQLException: SELECT statement contains a GROUP BY clause"
Does that mean that I should be using a GROUP BY clause or that it thinks there is one there when there actually isn't?
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stupid MicroSoft products.
That is a confusing message. Select statements are allowed to have group by clauses so I don't know why you would get that. Try prininting out the query string to see what is in it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic