在用eclipse连接mysql数据库时出现了解决不了的异常

Rainbowwwwww 2017-07-19 11:07:38
有段程序总是执行不了,但是我也找不到哪里不对,希望大神可以帮帮我。进行单元测试时报的异常是java.lang.ExceptionInInitializerError
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:217)
at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:266)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.NullPointerException
at java.util.Properties$LineReader.readLine(Unknown Source)
at java.util.Properties.load0(Unknown Source)
at java.util.Properties.load(Unknown Source)
at com.database.www.jdbconn.<clinit>(jdbconn.java:25)
... 22 more
折腾好久了都解决不了,下面是这段代码:



import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

import org.junit.Test;

public class jdbconn {
private static String url=null;
private static String user=null;
private static String password=null;
private static String classDriver=null;
static{
try {
//创建一个配置类对象
Properties prop = new Properties();
//读取db.properties文件
InputStream in = jdbconn.class.getResourceAsStream("/db.properties");
prop.load(in);//加载数据
url=prop.getProperty("url");//读取信息
user=prop.getProperty("user");
password=prop.getProperty("password");
classDriver=prop.getProperty("classDriver");
System.out.println(url);
Class.forName(classDriver);
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}

}
@Test
public void getConnection()throws Exception{
Connection conn = DriverManager.getConnection(url, user, password);
}
...全文
768 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Rainbowwwwww 2017-07-21
  • 打赏
  • 举报
回复
@shoppo0505 不是这个问题,没有拼写问题和标点符号的问题。真是想不通,可是这个问题解决不了,我就没办法通过在eclipse上写 程序对数据库进行操作
shoppo0505 2017-07-20
  • 打赏
  • 举报
回复
url=prop.getProperty("url");//读取信息 user=prop.getProperty("user"); password=prop.getProperty("password"); classDriver=prop.getProperty("classDriver"); 这几个属性在properties文件中都定义了没?拼写有错误me?

590

社区成员

发帖
与我相关
我的任务
社区描述
提出问题
其他 技术论坛(原bbs)
社区管理员
  • community_281
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧