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 'WHERE id = 1' at line 1
@Test
public void testResultet() {
Connection conn = null;
Statement statement = null;
ResultSet rs = null;
try {
//1获取Connection
conn = JDBCTools.getConnection();
//2获取Statement
statement = conn.createStatement();
//3准备sql
String sql = "SELECT id, name, email, birth" +
"FROM student WHERE id = 1 ";
//4执行查询,得到ResultSet
rs = statement.executeQuery(sql);
//5处理ResultSet
if(rs.next()) {
int id = rs.getInt(1);
String name = rs.getString("name");
String email = rs.getString(3);
Date birth = rs.getDate(4);
System.out.println(id);
System.out.println(name);
System.out.println(birth);
System.out.println(email);
}
} catch (Exception e) {
e.printStackTrace();
}finally {
//6关闭数据库资源
JDBCTools.relese(rs, statement, conn);
}
}
不知道上面的提示该怎么改 看着没有错呀 不知道哪里出现问题了 是数据库那里出现问题了 还是测试中的sql语句错了呢?