|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
Q1:
Driver driver = new com.mysql.jdbc.Driver();
String url = "jdbc.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false";
Properties info = new Properties();
info.put("user", "root");
info.put("password", "1230");
java.sql.Connection a = driver.connect(url, info);
System.out.println(a);
不知道链接成功没,没报错没警告
为什么输出的是null
Q2:
String driverClass=null;
String jdbcUrl=null;
String user = null;
String password = null;
//读取路径下的JDBC配置文件
InputStream in =
getClass().getClassLoader().getResourceAsStream("jdbc.properties");
Properties properties = new Properties();
properties.load(in);
driverClass = properties.getProperty("driver");
jdbcUrl = properties.getProperty("jdbcUrl");
user = properties.getProperty("user");
password = properties.getProperty("password");
Class.forName(driverClass);
java.sql.Connection connection = DriverManager.getConnection(jdbcUrl, user, password);
System.out.println(connection);
这个就直接报错了java.sql.SQLException: No suitable driver found for jdbc.url=jdbc:mysql://localhost:3306/test
mysql驱动导了没
你的url写错了不用这个jdbc.url=
|
|