所谓的动态sql就是在执行时输入参数
例如:
查询数据,数据让用户手动输入
@Test
public void selectData() throws Exception {
// 获取连接
Connection connection = ConnectionUtil.getConnection();
// 创建对象
Statement statement = connection.createStatement();
// 用户手动输入数据
Scanner scanner = new Scanner(System.in);
String id = scanner.next();
String sql = "select * from jdbc_test where id = " + id;
ResultSet resultSet = statement.executeQuery(sql);
while(resultSet.next()) {
int ids = resultSet.getInt(1);
String name = resultSet.getString("name");
double salary = resultSet.getDouble("salary");
System.out.println(ids + ":" + name + ":" + salary);
}
}
所谓的动态sql就是需要开发人员手动拼接字符串。但这样有一定问题