qq_36691241 2017-05-01 09:51 采纳率: 29.2%
浏览 891

关于JDBC奇葩的问题,请大神指教,搞了一天了,好蒙!!

代码如下package jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class FirstJDBCTest {

public static void main(String[] args) {
    FirstJDBCTest dao = new FirstJDBCTest();
    dao.findAll();
}
public void findAll() {
    Connection con = null;
    Statement stmt = null;
    ResultSet rs = null;
    try {
        Class.forName("oracle.jdbc.driver.OracleDriver");
        con = DriverManager.getConnection(
                "jdbc:oracle:thin:@localhost:1521:tarena", "scott", "123456");
        stmt = con.createStatement();
        rs = stmt
                .executeQuery("select empno, ename, sal, hiredate from emp");
        while (rs.next()) {
            System.out.println(rs.getInt("empno") + ","
                    + rs.getString("ename") + ","
                    + rs.getDouble("sal") + "," + rs.getDate("hiredate"));
        }
    } catch (ClassNotFoundException e) {
        System.out.println("驱动类无法找到!");
        throw new RuntimeException(e);
    } catch (SQLException e) {
        System.out.println("数据库访问异常!");
        throw new RuntimeException(e);
    } finally {
        try {
            if (rs != null) {
                rs.close();
            }
            if (stmt != null) {
                stmt.close();
            }
            if (con != null) {
                con.close();
            }
        } catch (SQLException e) {
            System.out.println("关闭连接时发生异常");
        }
    }
}

}
下面是相应的JAR包图片说明
下面是报错信息图片说明

  • 写回答

6条回答 默认 最新

  • 普通网友 2017-05-01 10:02
    关注

    确认你的库已经在classpath里

    try to follow this:

     The following are the steps that are given below to add ojdbc14.jar in eclipse:
    
    1) Inside your project
    
    2) Libraries
    
    3) Right click on JRE System Library
    
    4) Build Path
    
    5) Select Configure Build Path
    
    6) Click on Add external JARs...
    
    7) C:\oraclexe\app\oracle\product\10.2.0\server\jdbc\lib
    
    8) Here you will get ojdbc14.jar
    
    9) select here
    
    10) open
    
    11) ok
    
    save and run the program you will get output.
    

    try this
    http://stackoverflow.com/questions/15598757/oracle-jdbc-driver-oracledriver-classnotfoundexception

    评论

报告相同问题?

悬赏问题

  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3