public class ActionDb { public static void main(String[] args) throws SQLException { LoginDemo ld=new LoginDemo(); // 创建链接对象 Connection con; // 声明驱动名称 String driver = “com.mysql.jdbc.Driver”; // 找到链接的数据库的名称 String url = “jdbc:mysql://localhost:3306/buy”; // 输入用户名 String username = “root”; // 输入密码 String Password = “933032”; try { Class.forName(driver); con = DriverManager.getConnection(url, username, Password); Statement statement = null; try { statement = con.createStatement(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } String sql = “select * from user”; // String sql=" insert into user(ID,NAME)values(22,“shixinfa”) "; ResultSet rs = statement.executeQuery(sql); String name = null; String id = null; while (rs.next()) { // 获取stuname这列数据 name = rs.getString(“name”); // 获取stuid这列数据 id = rs.getString(“id”); boolean flag=ld.login(id,name); if (flag==true){ System.out.println(“登录成功”); } else{ System.out.println(“登录失败”); } // 输出结果 System.out.println(id + “\t” + name); } rs.close(); con.close(); if (!con.isClosed()) { System.out.println(“链接数据库成功了”); } else { System.out.println(“链接数据库失败了”); } } catch (ClassNotFoundException e) { e.printStackTrace(); } }

被折叠的 条评论
为什么被折叠?



