public static void main(String[] args) throws SQLException { long start = System.currentTimeMillis();//开始时间 new TestRead01().readPreparedStatement("daqing1"); long end = System.currentTimeMillis();//结束时就爱你 System.out.println("time:"+(end-start));//开始时间减去结束时间等于执行时间
start = System.currentTimeMillis();//开始时间 new TestRead01().readStatement("'or 1 or'"); end = System.currentTimeMillis();//结束时就爱你 System.out.println("time:"+(end-start));//开始时间减去结束时间等于执行时间 }
public void readPreparedStatement(String name) throws SQLException{ String sql = "select * from user where name=?"; conn = A0101JdbcUtils.getConnection(); ps = conn.prepareStatement(sql); ps.setString(1, name); rs = ps.executeQuery(); while(rs.next()){ System.out.println(rs.getObject(1)+"\t"+rs.getObject(2)+"\t"+rs.getObject(3)); } A0101JdbcUtils.free(rs, ps, conn); }
public void readStatement(String name) throws SQLException{ String sql = "select * from user where name='"+name+"'"; conn = A0101JdbcUtils.getConnection(); st = conn.createStatement(); rs = st.executeQuery(sql); while(rs.next()){ System.out.println(rs.getObject(1)+"\t"+rs.getObject(2)+"\t"+rs.getObject(3)); } } }