PreparedStatement 方法的setObject 与setString....的时间问题

代码如下:

public class Demo2 {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
//加载驱动
Class.forName("com.mysql.jdbc.Driver");
//url简写
String url="jdbc:mysql:///testjdbc";
String userName="root";
String password="root";
Connection conn=DriverManager.getConnection(url, userName, password);
String sql="insert into t_user(username,pwd,regTime) values(?,?,?)";
PreparedStatement pst=conn.prepareStatement(sql);
/*pst.setString(1,"aa");
pst.setString(2,"123");
pst.setDate(3,new java.sql.Date(System.currentTimeMillis()));*/
pst.setObject(1,"aa");
pst.setObject(2,"123");
pst.setObject(3,new java.sql.Date(System.currentTimeMillis()));

long start=System.currentTimeMillis();

pst.execute();
long end=System.currentTimeMillis();
System.out.println(end-start);

}
}

总结: 使用setObject 我测试了下时间是73,使用setString..时间是64,所以我觉得不使用setObject时间来算的话比较优化

 

posted @ 2017-01-09 00:11  耳朵像图图  阅读(9133)  评论(0编辑  收藏  举报