Hi:
I'm just trying a Java console application to talk to my MySQL. It appears that I can connect to my MySQL instance fine but I get error messages when I invoke a simple select command. Here is the error message.
Your SQL : select * from show
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 'show' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
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:2619)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2569)
at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1510)
at com.bdeshtv.java.DbTest.webbfactionDb(DbTest.java:107)
at com.bdeshtv.java.DbTest.main(DbTest.java:62)
And here is my Java class (part of code) that I"m using..
*public static void main(String[] args) throws Exception {
DbTest dbTest = new DbTest();
String sql = "select * from show";
dbTest.webbfactionDb(sql);
}
public String webbfactionDb(String sql) throws Exception {
try {
Class.forName("com.mysql.jdbc.Driver");
connect = DriverManager.getConnection("jdbc:mysql://web159.webfaction.com:3306/mydatabase","myuserid","mypassword");
statement = connect.createStatement();
resultSet = statement.executeQuery(sql);
writeResultSet(resultSet);
String resultStr = readAsString(resultSet);
return resultStr;
} catch (Exception e) {
throw e;
} finally {
close();
}
}*
Has anyone ran into this issue before? Thanks.
_Iqbal
asked
19 Jun '11, 23:05
iyusuf
1●1●2●4
accept rate:
0%
Can you try with "show tables" instead of the select query and use localhost for connection to the database?