Statement的方式
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(url,username,password);
Statement statement = con.createStatement();
ResultSet resultSet = statement.executeQuery("select * from users");
while (resultSet.next()) {
System.out.println(resultSet.getString(1));
System.out.println(resultSet.getString(2));
}
PreparedStatement
String sql = "select * from users where uid = ?";
Class.forName(name);
Connection connection = DriverManager.getConnection(url, username, password);
PreparedStatement preparedStatement = connection.prepareStatement(sql);
preparedStatement.setString(1,"111");
ResultSet resultSet = preparedStatement.executeQuery();