慕移动2145274
2019-03-03 21:52
package jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class Liu {
private static final String URL="jdbc:mysql://127.0.0.1:3306/imooc";
private static final String USER="root";
private static final String PASSWORD="123456";
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
Class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection(URL, USER, PASSWORD);
Statement stmt=conn.createStatement();
ResultSet rs= stmt.executeQuery("select user_name,age form imooc_goddess");
while(rs.next()) {
System.out.println(rs.getString("user_name")+","+rs.getInt("age"));
}
}
}
错误显示
Exception in thread "main" com.mysql.jdbc.exceptions.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 'imooc_goddess' at line 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3277)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3206)
at com.mysql.jdbc.Statement.executeQuery(Statement.java:1232)
at jdbc.Liu.main(Liu.java:17)
JDBC之 “ 对岸的女孩看过来”
99327 学习 · 856 问题
相似问题