数据库连接不上

a1009019814 2012-09-07 10:25:40
报错:java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
但是包已经导了, 而且是放在WebRoot/WEB-INF/lib下,怎么还是找不到包
...全文
122 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
a385528896 2012-09-10
  • 打赏
  • 举报
回复
这个不知道行吗,你试试
driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
url=jdbc:sqlserver://localhost:1433
user=root
pwd=1234
haorengoodman 2012-09-08
  • 打赏
  • 举报
回复
这种问题最好自己先单步一下。
jiuchengyi 2012-09-08
  • 打赏
  • 举报
回复
实话告诉你吧,你的driver写成了Driver
a1009019814 2012-09-07
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 的回复:]

配置文件中的driver没有写错吧?
[/Quote]
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/ems
user=root
pwd=1234
haorengoodman 2012-09-07
  • 打赏
  • 举报
回复
配置文件中的driver没有写错吧?
a1009019814 2012-09-07
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 的回复:]

看连接数据库的语句对吗,sql2000和sql2005,2008的不一样。。。看你用的什么版本数据库,对应什么语句
[/Quote]
数据库:mysql 5.0.18
sql语句:select*from emp where id=?
a385528896 2012-09-07
  • 打赏
  • 举报
回复
看连接数据库的语句对吗,sql2000和sql2005,2008的不一样。。。看你用的什么版本数据库,对应什么语句
a1009019814 2012-09-07
  • 打赏
  • 举报
回复
在啊,两个包都存在,ojdbc14,mysql-connector-java-5.1.6-bin
Cactus_hxk 2012-09-07
  • 打赏
  • 举报
回复
项目---右键---Properties---java build path---libraries 中看mysql的驱动包在不,如果不在再点击右侧的add jars 添加进来就可以了
a1009019814 2012-09-07
  • 打赏
  • 举报
回复
public class ConnectionFactory {
private static String driver = null;
private static String url = null;
private static String user = null;
private static String pwd = null;
private static Properties config = new Properties();
//闈欐€佹柟娉曟垨浠g爜鍧椾腑涓嶈兘璁块棶闈為潤鎬佹垚鍛?
static{
ClassLoader loader = ConnectionFactory.class.getClassLoader();
InputStream in = loader.getResourceAsStream("daconfig.properties");
try {
//宸茬粡灏嗗睘鎬ф枃浠朵腑鐨勫唴瀹瑰瓨鍒癱onfig瀵硅薄閲岄潰
config.load(in);
driver = config.getProperty("driver");
url = config.getProperty("url");
user = config.getProperty("user");
pwd = config.getProperty("possword");
} catch (IOException e) {
e.printStackTrace();
}finally{
if(in!=null){
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public static Connection getConnection(){
Connection con = null;
try {
Class.forName(driver);
con = DriverManager.getConnection(url,user,pwd);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return con;
}
public static void main(String[] args) {
Connection con = ConnectionFactory.getConnection();
System.out.println(con);
}
}
bushixiaoyao 2012-09-07
  • 打赏
  • 举报
回复
try...catch了没有,如果能有代码更能清楚你的问题

67,538

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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