1

我正在尝试在 Java Web 项目中连接到 Oracle 数据库,这是我得到的例外:

 java.sql.SQLException: Exception d'E/S: Got minus one from a read
 call at
 oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134) at
 oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179) at
 oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:333) at
 oracle.jdbc.driver.OracleConnection.(OracleConnection.java:404) at
 oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:468)
 at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:314) at
 java.sql.DriverManager.getConnection(Unknown Source) at
 java.sql.DriverManager.getConnection(Unknown Source) at
 mypack1.login.doPost(login.java:60) at
 javax.servlet.http.HttpServlet.service(HttpServlet.java:641) at
 javax.servlet.http.HttpServlet.service(HttpServlet.java:722) at
 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
 at
 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
 at
 org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
 at
 org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
 at
 org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
 at
 org.ow2.jonas.web.tomcat7.CheckOpenResourcesValve.invoke(CheckOpenResourcesValve.java:69)
 at
 org.ow2.jonas.web.tomcat7.tx.TransactionValve.invoke(TransactionValve.java:89)
 at
 org.ow2.jonas.web.tomcat7.ResetAuthenticationValve.invoke(ResetAuthenticationValve.java:95)
 at
 org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
 at
 org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
 at
 org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
 at
 org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
 at
 org.ow2.jonas.web.tomcat7.versioning.VersioningValve.invoke(VersioningValve.java:105)
 at
 org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
 at
 org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
 at
 org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
 at
 org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
 at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
 at java.lang.Thread.run(Unknown Source)

这是我的连接代码:

try {
    Class.forName("oracle.jdbc.OracleDriver");
} catch (ClassNotFoundException e) {
    StringWriter sw = new StringWriter();
    e.printStackTrace(new PrintWriter(sw));
    String exceptionAsString = sw.toString();
    out.println("<html><head><title>Hello World</title></head><body>");
    out.println ("<h1>Where is your Oracle JDBC Driver?</h1>"+exceptionAsString+"</body></html>");      
    return;
}
out.println("<html><head><title>Hello World</title></head><body>");
out.println ("<h1>Oracle JDBC Driver Registered!</h1></body></html>");
Connection connection = null;
try {
    connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:3010/apex/:XE","JEE","admin");
} catch (SQLException e) {
    StringWriter sw = new StringWriter();
    e.printStackTrace(new PrintWriter(sw));
    String exceptionAsString = sw.toString();
    out.println("<html><head><title>Hello World</title></head><body>");
    out.println ("<h1>Connection Failed! Check output console</h1>"+exceptionAsString+"</body></html>");
    e.printStackTrace();
    return;
}
if (connection != null) {
    out.println("<html><head><title>Hello World</title></head><body>");
    out.println ("<h1>You made it, take control your database now!</h1></body></html>");
} else {
    out.println("<html><head><title>Hello World</title></head><body>");
    out.println ("<h1>Failed to make connection!</h1></body></html>");
}
4

0 回答 0