主题:大家帮忙看下这段程序
首先环境变量没有错误 ,找其他程序测试过,可以执行
编译通过。运行不了
Exception in thread "main" java.lang.NoClassDefFoundError: JDBCExample
import java.util.*;
import java.sql.*;
public class JDBCExample {
/**
* @param args
*/
public static void main(String[] args) {
String oraclederiver= "oracle.jdbc.driver.OracleDriver";
String url="jdbc:oracle:thin@ORACLE9I";
String username="scott";
String password="tiger";
String sql= "insert users values(?,?)";
try {
Class.forName(oraclederiver);
Connection conn=DriverManager.getConnection(url,username,password);
PreparedStatement psmt=conn.prepareStatement(sql);
psmt.setString(1, "tom");
psmt.setString(2, "1234");
psmt.executeUpdate();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// TODO Auto-generated method stub
}
}
编译通过。运行不了
Exception in thread "main" java.lang.NoClassDefFoundError: JDBCExample
import java.util.*;
import java.sql.*;
public class JDBCExample {
/**
* @param args
*/
public static void main(String[] args) {
String oraclederiver= "oracle.jdbc.driver.OracleDriver";
String url="jdbc:oracle:thin@ORACLE9I";
String username="scott";
String password="tiger";
String sql= "insert users values(?,?)";
try {
Class.forName(oraclederiver);
Connection conn=DriverManager.getConnection(url,username,password);
PreparedStatement psmt=conn.prepareStatement(sql);
psmt.setString(1, "tom");
psmt.setString(2, "1234");
psmt.executeUpdate();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// TODO Auto-generated method stub
}
}