import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class PreparedStatementDemo {
public static void main(String[] args) {
Connection conn=null;
PreparedStatement pstmt=null;
String []id={“1”,”2”,”3”};
String []name={“lancy”,”tom”,”jerry”};
try {
//加载驱动
Class.forName(“com.mysql.jdbc.Driver”);
System.out.println(“驱动加载成功”);
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}
try {
//获得数据库连接
conn = DriverManager
.getConnection(“jdbc:mysql://localhost/student?user=root&password=sa”);
System.out.println(“获得数据库连接”);
//获得语句对象
pstmt=conn.prepareStatement(“insert into student values(?,?)”);
//执行sql语句
long t1=System.nanoTime();
for(int i=0;i
查询数据库PreparedStatement
最新推荐文章于 2024-04-27 22:32:52 发布