日期:2014-05-20  浏览次数:20901 次

数据库错误
import   java.sql.*;

public   class   TestConnection   {
static{
try{
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver ");
System.out.println( "Success   loading   JDBC-ODBC   Bridge   Driver...\n ");
}catch(Exception   e){
System.out.println( "Error   loading   JDBC-ODBC   Bridge   Driver...\n ");
e.printStackTrace();
}
}
public   static   void   main(String   args[]){
try{
Connection   con   =   DriverManager.getConnection( "jdbc:odbc:table ", "root ", "******** ");
System.out.println( "Success   eastablishing   the   Connection ");
Statement   state   =   con.createStatement();
ResultSet   result   =   state.executeQuery( "select   *   from   table ");
while(result.next()){
String   Id=   result.getString(1);
                  String   name=   result.getString(2);
String   age=   result.getString(3);
String   score=   result.getString(4);
String   number=   result.getString(5);
}
con.close();
}catch(Exception   e){
e.printStackTrace();
}
}

}

错误如下,在eclipse中运行
Success   loading   JDBC-ODBC   Bridge   Driver...

Success   eastablishing   the   Connection
java.sql.SQLException:   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   'table '   at   line   1
at   sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown   Source)
at   sun.jdbc.odbc.JdbcOdbc.standardError(Unknown   Source)
at   sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(Unknown   Source)
at   sun.jdbc.odbc.JdbcOdbcStatement.execute(Unknown   Source)
at   sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(Unknown   Source)
at   TestConnection.main(TestConnection.java:18)

------解决方案--------------------
java.sql.SQLException: 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 'table ' at line 1

SQL语句 语法错误
你数据库里的表名叫table吗