一月二十六日 安卓开发五
书接上回 继续完善连接数据库的代码
package com.example.test2; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; public class data { public static int getUserSize(){ final String CLS="com.mysql.jdbc.Driver"; final String URL="jdbc:mysql://192.168.60.241:3306/期末考试"; final String USER="root"; final String PWD="123456"; int count=0; try{ Class.forName(CLS); Connection conn= DriverManager.getConnection(URL,USER,PWD); String sql="select count(1) as root from 账号管理"; Statement stmt=conn.createStatement(); ResultSet rs=stmt.executeQuery(sql); while(rs.next()){ count=rs.getInt("root"); } }catch (Exception ex){ ex.printStackTrace(); } return count; } }