Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> help on servlet connection to oracle8i
Hi all,
Recently I installed Oracle8i on my NT machine and tried to use servlet to connect to the starter database. The story was not successful. However, I could run the sample file (JdbcCheckup.java) that comes with Oracle8i which showed that the JDBC installation on Oracle8i was correct. The strange thing is that I have used the same connection code as that in the JdbcCheckup.java.
Here I have provide some servlet codes. The program compiles but the connection could not be established. The program only outputs "before registration".
Thanks so much for any suggestion.
Stephen
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*; import java.io.*; import java.sql.*; import java.net.URL;
public class TestOracle8i extends HttpServlet {
public String getServletInfo()
{
return "A JDBC Servlet Example";
}
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
Connection con = null;
try {
out.println("before registration");
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
out.println("registration ok");
con = DriverManager.getConnection("jdbc:oracle:oci8:@startdb", "scott", "tiger");
out.println("Connection is good");
}
catch (Exception e) {}
// Any error is grounds for rollback try {
con.rollback();
}
catch (Exception ignored) {
//out.println("Order failed. Please contact technical support.");
}
finally {
// Clean up. try { if (con != null) con.close(); } catch (SQLException ignored) { }