时间:2021-07-01 10:21:17 帮助过:25人阅读
model
package model;
import java.io.Serializable;
public class Student implements Serializable{
private int id;
private int age;
private String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
测试
package model;
import java.sql.ResultSet;
import java.sql.SQLException;
import util.JdbcUtil;
public class Test {
public static void main(String[] args) {
testInsert();
testQuery();
}
public static void testInsert(){
Student s=new Student();
s.setId(12);
s.setAge(23);
s.setName("xxt");
JdbcUtil u=new JdbcUtil();
String sql="insert into T_Student(id,age,name) values( ?,?,?)";
int result=u.update(sql, s.getId(),s.getAge(),s.getName());
System.out.println(result);
}
public static void testQuery(){
String sql="select * from T_Student where age=?";
Student s=new Student();
s.setAge(23);
JdbcUtil u=new JdbcUtil();
ResultSet rs=u.Query(sql, s.getAge());
try {
if(rs.next()){
//s.setName(rs.getString("name"));
System.out.println(rs.getString("name"));//s.getName(rs.getString("name"))
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
jdbc工具类封装
标签:iter author data- keyword localhost select func type count