新人学JDBC连接mysql 出问题了!求助!
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 用的是myeclipse jdk1.6 JUnit4的test mysql驱动导了没
你的url写错了不用这个jdbc.url= 夜色下的俯瞰 发表于 2018-3-14 23:13
mysql驱动导了没
你的url写错了不用这个jdbc.url=
谢谢,的确是URL写错了
页:
[1]