附上代码,我自己在数据库中建的conn数据库密码时mysql
public class DBTest {
@Test
public void test() {
final String url="jdbc:mysql://localhost:3306/conn";
final String user="root";
final String password="mysql";
try {
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection(url, user, password);
System.out.println(conn);
}
catch(ClassNotFoundException e) {
e.printStackTrace();
System.out.println("未找到驱动程序");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("数据库连接出现异常");
}
}
}
qq_a沙漏中的时光_0
望远