-
mysql-connector-java-5.1.48.zip下载
资源介绍
Android连接MySQL数据库驱动架包,连接使用 // Android 4.0 之后不能在主线程中请求HTTP请求
new Thread(new Runnable(){
@Override
public void run() {
try {
Class.forName("com.mysql.jdbc.Driver");
//获取数据库连接对象url=jdbc:mysql://IPAddress:3306/DatabaseName
connection= DriverManager.getConnection("jdbc:mysql://192.168.1.99:3306/root","root","root");
String sql="select * from user";//查询表中的所有内容
Statement statement=connection.createStatement();//创建Statement
ResultSet rs=statement.executeQuery(sql);
while (rs.next()){
sbmysql.append(rs.getInt("id")+"\t"+rs.getString("username")+"\t"+rs.getString("password")+"\n");
}
textdata.setText(sbmysql.toString());
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
textdata.setText(e.toString());
}
}
}).start();