67,513
社区成员
发帖
与我相关
我的任务
分享
public class TestJdbc {
private static List<TestBean> tbs;
public static void main(String[] args) {
String url ="jdbc:mysql://localhost/testjdbc?user=root&password=root&useUnicode=true&characterEncoding=8859_1";
TestBean tb=new TestBean();
ResultSet rs=null;
try {
Connection conn= DriverManager.getConnection(url);
Statement stmt=conn.createStatement();
rs=stmt.executeQuery("select * from test");
while(rs.next()){
tb.setId(rs.getLong("id"));
tb.setName(rs.getString("name"));
tb.setPassword(rs.getString("password"));
tbs.add(tb);
}
for(TestBean tb1: tbs){
System.out.println(tb1.getName());
System.out.println(tb1.getPassword());
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}