手机可以连接mysql数据库
今天,在移动互联网时代,手机已经成为了人们生活和工作的必需品。各种应用程序和网页上的数据需要在手机端展示和操作,而这些数据都存储在数据库中。现在,手机可以通过连接MySQL数据库来实现对这些数据的操作。
//连接数据库 try { Class.forName("com.mysql.jdbc.Driver"); Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "123456"); //执行SQL语句 Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM students"); //遍历结果集 while (rs.next()) { String name = rs.getString("name"); int age = rs.getInt("age"); System.out.println("name: "+name+", age: "+age); } //关闭连接 rs.close(); stmt.close(); conn.close(); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); }