时间:2021-07-01 10:21:17 帮助过:3人阅读
1 package org.test; 2 3 import java.sql.Connection; 4 import java.sql.PreparedStatement; 5 import java.sql.ResultSet; 6 import java.sql.SQLException; 7 8 import org.db.DBConn; 9 import org.model.Login; 10 11 public class test { 12 13 public static void main(String[] args) { 14 Connection conn = DBConn.getConn(); 15 if (conn!=null) { 16 System.out.println("连接成功"); 17 try { 18 conn = DBConn.getConn(); 19 String sql = "select id,name,password,role from mbook where name=? and password=?"; 20 PreparedStatement ps = conn.prepareStatement(sql); 21 ps.setString(1,"张三"); 22 ps.setString(2,"000000"); 23 ResultSet rs = ps.executeQuery(); 24 25 while (rs.next()) { 26 Login login = new Login(); 27 login.setId(rs.getInt(1)); 28 login.setName(rs.getString(2)); 29 login.setPassword(rs.getString(3)); 30 login.setRole(rs.getBoolean(4)); 31 System.out.println("得到数据:"+login); 32 } 33 } catch (SQLException e) { 34 e.printStackTrace(); 35 }finally{ 36 DBConn.closeConn(); 37 } 38 } 39 } 40 }
jdbc 简易 模板
标签:org com password username use java cte tco pass