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
我在网上搜了几天,都没有解决这个问题
大家帮帮我吧