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

//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个回答

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

SonOfWind0311
SonOfWind0311 回复qq_31973715: 表名大小写是不是一致?
大约 3 年之前 回复
qq_31973715
qq_31973715 建了,emp应该没问题,是在oracle 中
大约 3 年之前 回复
qq_31973715
qq_31973715 建了,是在oracle 中
大约 3 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐