当前位置: 首页 > 知识库问答 >
问题:

我不能在上面的select语句中插入数据?有人能帮我吗?[关闭]

狄阳华
2023-03-14

大家都能看到这张图

case 3:
                    System.out.println("Tìm kiếm sinh viên theo tên sinh viên :" );
                    String search = sc.nextLine();
                    Connection connection2 = JdbcApplication.JDBCConnection();
                    Statement statement3 = JdbcApplication.JDBCConnection().createStatement();
                    String sql4 = "select * from student where name = ?   ";
                    PreparedStatement preparedStatement = connection2.prepareStatement(sql4);
                    preparedStatement.setString(1,search);
                    ResultSet resultSet4 =preparedStatement.executeQuery(sql4);
                    while (resultSet4.next()) {
                        int id = resultSet4.getInt("id");
                        int code2 = resultSet4.getInt("code");
                        String name2 = resultSet4.getString("name");
                        System.out.println("id:" + id + " " + "code: " + " " + code2 + " " + "name: " + " " + name2);
                        break;
                    }

共有1个答案

吴俊晤
2023-03-14

删除末尾多余的空格,然后再试一次。

String sql4=“select*from student where name=?”;

还打印搜索变量的值,以查看是否如您所期望的那样正确。

 类似资料: