鱼C论坛

 找回密码
 立即注册
查看: 2613|回复: 3

[已解决]新人学JDBC连接mysql 出问题了!求助!

[复制链接]
发表于 2018-3-14 23:03:26 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

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
最佳答案
2018-3-14 23:13:38
mysql驱动导了没
你的url写错了不用这个jdbc.url=
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2018-3-14 23:06:10 | 显示全部楼层
用的是myeclipse jdk1.6 JUnit4的test
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-3-14 23:13:38 | 显示全部楼层    本楼为最佳答案   
mysql驱动导了没
你的url写错了不用这个jdbc.url=
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-3-15 13:30:39 | 显示全部楼层
夜色下的俯瞰 发表于 2018-3-14 23:13
mysql驱动导了没
你的url写错了不用这个jdbc.url=

谢谢,的确是URL写错了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-20 10:06

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表