File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Help with SQL syntax. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Help with SQL syntax." Watch "Help with SQL syntax." New topic
Author

Help with SQL syntax.

Craig Snowbarger
Ranch Hand

Joined: Mar 07, 2001
Posts: 38
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

Joined: May 05, 2000
Posts: 13974
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).]


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Craig Snowbarger
Ranch Hand

Joined: Mar 07, 2001
Posts: 38
So would I do that like this?
String query = "SELECT Make FROM Equipment" + " " + "WHERE TestSetID =" + list.getSelectedValue();
Craig Snowbarger
Ranch Hand

Joined: Mar 07, 2001
Posts: 38
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

Joined: May 05, 2000
Posts: 13974
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

Joined: Mar 07, 2001
Posts: 38
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

Joined: May 05, 2000
Posts: 13974
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help with SQL syntax.