本人 先测试了与数据库的链接 发现没有问题 但我编写了一个删除一条记录的测试程序后 发现出现了异常 查了半天资料 也没发现问题在哪 望哪位好心人帮忙看下
这 是测试程序:package org.lxh.demo17.preparedstatementdemo;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import
java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class PreparedSatementDome01 {
public static final String DBDRIVER="org.git.mm.mysql.Driver";
public static final String DBURL="jdbc:mysql://localhost:3306/mldn";
public static final String DBUSER="root";
public static final String DBPASSWORD="root";
public static void main(String[] args) {
Connection conn=null;
try{
Class.forName(DBDRIVER);
}catch(
ClassNotFoundException e){
e.printStackTrace();
}
try{
conn=DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD);
}catch(
SQLException e){
e.printStackTrace();
}
System.out.print(conn);
try{
conn.close();
}catch(SQLException e){
e.printStackTrace();
}
}
}程序结果:
java.lang.ClassNotFoundException: org.git.mm.mysql.Driver
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at org.lxh.demo17.preparedstatementdemo.PreparedSatementDome01.main(PreparedSatementDome01.java:16)
com.mysql.jdbc.JDBC4Connection@1292d26
这是测试删除的程序:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
public class DeleteDemo {
public static final String DBDRIVER="com.mysql.jdbc.Driver ";
public static final String DBURL="jdbc:mysql://localhost:3306/test";
public static final String DBUSER="root";
public static final String DBPASSWORD="root";
public static void main(String[] args) throws Exception {
Connection conn=null;
Statement stmt=null;
int id=1;
String sql="delete from user where id="+id;
Class.forName(DBDRIVER);
conn=DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD);
stmt=conn.createStatement();
stmt.executeUpdate(sql);
stmt.close();
conn.close();
}
}
结果却出现异常:
Exception in thread "main" java.lang.Class
NotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.l