标题:[求助]ecplipse中连mysql问题
取消只看楼主
tigershi10
Rank: 1
等 级:新手上路
帖 子:84
专家分:0
注 册:2006-10-12
 问题点数:0 回复次数:1 
[求助]ecplipse中连mysql问题

package mypackage;

import java.sql.*;

public class DataConnection
{
public static void main(String[] args)
{
String driver = "com.mysql.jdbc.driver";
String url = "jdbc:mysql://localhost/mydatabase";
String user="root";
String password="tiger";
try
{
Class.forName(driver);
Connection con= DriverManager.getConnection(url, user, password);
String insert ="insert friends(id,name) values (?,?)";
PreparedStatement prestatement=con.prepareStatement(insert);
String[] names={"liu","qian","shi","xu","zhou","lu"};
for(int i=0;i<6;i++)
{
prestatement.setInt(1, i);
prestatement.setString(2, names[i]);
prestatement.execute();
}
String query="select * from friends";
ResultSet result=(ResultSet) prestatement.executeQuery(query);
while(result.next())
{
System.out.println(result.getString("name"));
}
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}
catch (SQLException e)
{
e.printStackTrace();
}

}

}
这是我的程序
已经加载了mysql-connector-java-5.0.6-bin.jar和mysql-connector-java-5.0.6-bin-g.jar包
但总是出现
java.lang.ClassNotFoundException: com.mysql.jdbc.driver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at mypackage.DataConnection.main(DataConnection.java:16)
这个错误
明明驱动我已经加载了
mysql我用的是5.0
我在网上搜了几天,都没有解决这个问题
大家帮帮我吧

搜索更多相关主题的帖子: ecplipse mysql 
2007-05-28 13:14
tigershi10
Rank: 1
等 级:新手上路
帖 子:84
专家分:0
注 册:2006-10-12
得分:0 

有人会吗?
教教我哦


专业源于品质
2007-05-28 17:22



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-142955-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.139827 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved