jdbc 测试时出现错误(包括数据库语句)

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语句错了呢?

 String sql = "SELECT id, name, email, birth" +
        "FROM student WHERE id = 1 ";

应该修改为:

 String sql = "SELECT id, name, email, birth" +
        " FROM student WHERE id = 1 ";

否则 birth和FROM就两个单词就连到一起了。

用心回答每个问题,如果对您有帮助,请采纳答案好吗,谢谢。

SELECT id, name, email, birth 有逗号 去掉逗号。 然后 from 前面加空格

sql错了,from前或者birth后加个空格