3.5

进行了Androidstdio的安装与配置,这是连接数据库的代码

public class JDBCUtils {

private static String driver = "com.mysql.jdbc.Driver";// MySql驱动
private static String dbName = "face";// 数据库名称
private static String user = "root";// 用户名
private static String password = "a123456";// 密码

public static Connection getConn(){
Connection connection = null;
try{
Class.forName(driver);// 动态加载类
String ip = "192.168.32.174";// 写成本机地址,不能写成localhost,同时手机和电脑连接的网络必须是同一个

// 尝试建立到给定数据库URL的连接
connection = DriverManager.getConnection("jdbc:mysql://" + ip + ":3306/" + dbName + "?characterEncoding=UTF-8",
user, password);
}catch (Exception e){
e.printStackTrace();
}
return connection;
}
}
posted @ 2024-03-05 23:39  涨涨涨张  阅读(3)  评论(0编辑  收藏  举报