qq_31973715 2017-07-25 14:40 采纳率: 0%
浏览 755

各位大神,麻烦帮看下我这段代码到底是哪里的问题:不胜感激!!!

//1
package package1;

import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

import org.apache.commons.dbcp.BasicDataSource;

public class DBUtil {
private static BasicDataSource ds;

static{
    Properties p = new Properties();
    try {
        p.load(DBUtil.class.getClassLoader().getResourceAsStream("db.perproties"));
        String driver = p.getProperty("driver");
        String url = p.getProperty("url");
        String user = p.getProperty("user");
        String pwd = p.getProperty("pwd");
        String initsize = p.getProperty("initsize");
        String maxsize = p.getProperty("maxsize");
        ds = new BasicDataSource();
        ds.setDriverClassName(driver);
        ds.setUrl(url);
        ds.setUsername(user);
        ds.setPassword(pwd);
        ds.setInitialSize(new Integer(initsize));
        ds.setMaxActive(new Integer(maxsize));

    } catch (IOException e) {
        e.printStackTrace();
        throw new RuntimeException("读取配置文件异常",e);
    }
}

public static Connection getConnection() throws SQLException{
    return ds.getConnection();
}
public static void closeConnection(Connection conn){
    if(conn!=null){
        try {
            conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
            throw new RuntimeException("关闭连接异常",e);
        }
    }
}
public static void rollBack(Connection conn){
    if(conn!=null){
        try {
            conn.rollback();
        } catch (SQLException e) {
            e.printStackTrace();
            throw new RuntimeException("回滚操作异常",e);
        }
    }
}

}
//2
driver=oracle.jdbc.driver.OracleDriver
url=jdbc:oracle:thin:@localhost:1521:orcl
user=SYSTEM
pwd=MINg4978
initsize=1
maxsize=3

//3
/**
* 根据ID查看一个员工
/
public Emp findById(int id) {
Connection conn = null;
Emp e = null;
try {
conn = DBUtil.getConnection();
System.out.println("连接池创建成功");
String sql = "select * from emp where empno = ?";
System.out.println(11);
PreparedStatement ps = conn.prepareStatement(sql);
System.out.println(22);
ps.setInt(1, id);
System.out.println(33);
ResultSet rs = ps.executeQuery();
System.out.println(44);
if (rs.next()) {
e = createEmp(rs);
return e;
}
} catch (Exception e1) {
e1.printStackTrace();
throw new RuntimeException("查询员工异常", e1);
} finally {
DBUtil.closeConnection(conn);
}
return null;
}
/
*
控制台输出结果是这样的:
连接池创建成功
11
22
33
java.sql.SQLException: ORA-00942: 表或视图不存在

at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:745)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:216)
at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:810)
at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1039)
at oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStatement.java:850)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1134)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3339)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3384)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
at packageEmp.EmpDao.findById(EmpDao.java:85)
at TestPackage.Test01.main(Test01.java:9)

Exception in thread "main" java.lang.RuntimeException: 查询员工异常
at packageEmp.EmpDao.findById(EmpDao.java:93)
at TestPackage.Test01.main(Test01.java:9)
Caused by: java.sql.SQLException: ORA-00942: 表或视图不存在

at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:745)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:216)
at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:810)
at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1039)
at oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStatement.java:850)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1134)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3339)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3384)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
at packageEmp.EmpDao.findById(EmpDao.java:85)
... 1 more
  • 写回答

1条回答

  • SonOfWind0311 2017-07-26 02:01
    关注

    表emp建了吗?是在orcl数据库中吗?

    评论

报告相同问题?

悬赏问题

  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B
  • ¥15 想问一下stata17中这段代码哪里有问题呀
  • ¥15 flink cdc无法实时同步mysql数据