3月27日 JavaWeb 周二

xiaoxiao2021-02-28  18

/* hao * 2018-3-27 20:57:05 * JDBC查询 * "jdbc:mysql://localhost:3306/yy2018", "root", "root" */ package java_web; import java.sql.Connection; import java.sql.DriverManager;//唯一的一个类 import java.sql.ResultSet; import java.sql.Statement; public class JDBC { public static void main(String[] args) { try { Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/yy2018", "root", "root"); Statement sc = con.createStatement(); String sql = "select * from user01"; ResultSet rs = sc.executeQuery(sql); while(rs.next()){ System.out.println("提取账号: "+rs.getInt(1)+"提取密码: "+rs.getInt(2)); } if(rs!=null){ rs.close(); } if(sc!=null){ sc.close(); } if(con!=null){ con.close(); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }

永远不要太自以为是,谁知道自己在别人眼里是一副什么模样

转载请注明原文地址: https://www.6miu.com/read-1600259.html

最新回复(0)