手机访问mysql直接用jdbc吗

手机访问MySQL数据库的方式有很多种,其中使用JDBC是一种经过验证的可靠方式。然而,直接在手机上使用JDBC可能存在一些问题。

String url = "jdbc:mysql://yourHost:yourPort/yourDatabaseName"; String user = "yourUsername"; String password = "yourPassword"; try { Class.forName("com.mysql.jdbc.Driver"); Connection conn = DriverManager.getConnection(url, user, password); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM yourTableName"); while (rs.next()) { String name = rs.getString("name"); int age = rs.getInt("age"); // do something with the data } rs.close(); stmt.close(); conn.close(); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); }