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 why do I get this exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "why do I get this exception" Watch "why do I get this exception" New topic
Author

why do I get this exception

ben riches
Ranch Hand

Joined: Nov 08, 2002
Posts: 126
Hello All,
When I click on a table name called 00_BPDCON I get the Exception:
SQL Exception: java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL Server] Line 1: Incorrent Syntax near '00' .
I don't know why this is happerning?

Rgds
Ben
Chris Hall
Ranch Hand

Joined: Dec 04, 2002
Posts: 39
Since its a SQLException, the problem lies in the sql statement you are executing, which in this case is select * from {tableName] where 1=0 . Assuming the table name is correct, the 'where 1=0' means you have a field called 1 and you are looking for the records of that field with a value of 0. This really doesn't make sense, and I would guess that is the root of your problem. Make sure you know the structure of the database, and you can try executing the sql statement directly against the database to make sure it works.
Wayne L Johnson
Ranch Hand

Joined: Sep 03, 2003
Posts: 399
Chris' reply is correct in that you should print out the query as it is being executing, and try executing it directly against the database to verify it.
However the query, "Select * from <tablename> where 1=0" is a perfectly valid query in most databases (I've used it against Oracle, Sybase and MySql) and is a great way to get the table's column definition. It executes very fast and returns no rows, but you still get the MetaData so you can pull out the number of columns, and column names and types.
The error message seems to indicate it doesn't like the table name. However test the SQL directly against your SQL-Server database to make sure that it supports the query.
Finally, and this is a minor issue, but you should probably close your resultset explicitly. Some database don't care, but with some databases you need to close both the resultset and statement. And that should be done in a "finally" clause to ensure they get closed even if an exception gets thrown.
mani pallapu
Greenhorn

Joined: Mar 11, 2004
Posts: 2
Originally posted by Chris Hall:
Since its a SQLException, the problem lies in the sql statement you are executing, which in this case is select * from {tableName] where 1=0 . Assuming the table name is correct, the 'where 1=0' means you have a field called 1 and you are looking for the records of that field with a value of 0. This really doesn't make sense, and I would guess that is the root of your problem. Make sure you know the structure of the database, and you can try executing the sql statement directly against the database to make sure it works.
ben riches
Ranch Hand

Joined: Nov 08, 2002
Posts: 126
So how can I pull all the tablenames out from the database without looking for 1?
Ben
Dana Hanna
Ranch Hand

Joined: Feb 28, 2003
Posts: 227
DatabaseMetadata has a method for getting column names!
And the 1=0 trick on DB2 for OS/390 takes FOREVER to execute - Don't ask me why!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why do I get this exception
 
Similar Threads
combining two classes
why is my JTable not showing up?
Jtable cells
Stll having problems
Thowing to many errors