import java.sql.*;
public class TestPreparedStatement {
public static void main(String[] args) {
add("12","GTA","动作");
static void add(String string;String string2;String string3) {
Connection conn=null;
PreparedStatement stmt=null;
try{
Class.forName("com.mysql.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:mysql://localhost/test?"+
"user=root&password=710309471&useSSL=true");
String sql="insert games values (?,?,?)";
stmt=conn.prepareStatement(sql);
stmt.setString(1,string);
stmt.setString(2, string2);
stmt.setString(3, string3);
System.out.println(sql);
stmt.executeUpdate();
}catch(ClassNotFoundException e){
e.printStackTrace();
}catch(SQLException ex){
System.out.println("SQLException"+ex.getMessage());
System.out.println("SQLState"+ex.getSQLState());
System.out.println("VendorError"+ex.getErrorCode());
}finally{
try{
if(conn!=null){
conn.close();
conn=null;
}
}catch(SQLException e){
e.printStackTrace();
}
}
}
}
}