String url = "jdbc:mysql://localhost:3306/test";
String user = "root";
String password = "110";
Connection conn = null;
PreparedStatement pstmt = null;
String driverName = "com.mysql.jdbc.Driver";
try {
Class.forName(driverName).newInstance();
conn = DriverManager.getConnection(url, user, password);
} catch (ClassNotFoundException e) {
out.println(e);
} catch (SQLException e) {
out.println("连接SQLserver数据库失败!!!!!!");
}
本文展示了一个使用Java连接MySQL数据库的示例代码,包括设置数据库URL、用户名、密码,加载MySQL驱动,以及通过DriverManager获取数据库连接的过程。
150

被折叠的 条评论
为什么被折叠?



