-
January 15th, 2012, 02:25 PM
#1
MySql Error in Java program
Hello,
I'm not really sure if this is the right area i should be putting this(so i'm going to post it both in mysql section and this section) but here is the problem.
I am getting the following error
Code:
Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '> 2010-01-15 ORDER BY date ASC LIMIT 1' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3597)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3529)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1990)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2151)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2625)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2119)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2281)
at Main.Database.execute(Database.java:153)
at Analysis.Analysis_A.main(Analysis_A.java:40)
The problem is, my code seems right because when i plug it into the actual SQL query box in MySql it runs perfectly fine.
Here is the code that is erroring up:
Code:
Date date = (Date) RS.getObject(1);
double percentChange = RS.getDouble("percentChange");
ResultSet RS2 = newConnection.execute("SELECT date, percentChange FROM " + tickerMaster[x] + "WHERE date > " + date + " ORDER BY date ASC LIMIT 1");
I am obtaining the box contents using an object, however i am parsing it as an SQL Date. I have also tried using getDate(1).
If you could help, it would be greatly appreciated
-Alex
-
January 16th, 2012, 11:39 AM
#2
Re: MySql Error in Java program
This is an SQL problem and not a Java problem.
I suggest you change your code to output the actual sql string you are executing to the console and then cut and paste the output sql text into the MySql command line and see if it runs.
-
January 16th, 2012, 11:40 AM
#3
Re: MySql Error in Java program
Originally Posted by Alexz003
The problem is, my code seems right because when i plug it into the actual SQL query box in MySql it runs perfectly fine.
You're saying that when you do this:
Code:
String sql = "SELECT date, percentChange FROM " + tickerMaster[x] + "WHERE date > " + date + " ORDER BY date ASC LIMIT 1";
System.out.println(sql);
ResultSet RS2 = newConnection.execute(sql);
...and copy the output from the System.out.println(sql) command & paste it directly into the SQL query box in MySql it runs perfectly fine??
-
January 16th, 2012, 03:25 PM
#4
Re: MySql Error in Java program
Also posted (and answered) in the Database forum (here). The problem was a missing space between the table name and WHERE:
Code:
... FROM " + tickerMaster[x] + "WHERE ...
-
January 16th, 2012, 04:04 PM
#5
Re: MySql Error in Java program
Thanks for the update jcaccia.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|