Forum Stats

  • 3,817,470 Users
  • 2,259,339 Discussions
  • 7,893,789 Comments

Discussions

Problem connecting oracle database to jsp pages using Apache Tomcat server 8.0

Chanda Roy
Chanda Roy Member Posts: 2
edited Jun 1, 2014 6:05AM in ODBC

Well...I tried too many things..googled so many times..but still could not find solution to my problem.

I use windows 8 Enterprise Edition(if this has to do something with the problem)

Oracle 11.2.0

Apache Tomcat server 8.0

JDK 1.7

My oracle is installed in the D: drive and tomcat in c:. i copied the ojdbc6.jar file from oracle to lib directory of tomcat server.

Then i set  CLASSPATH in environment variables as "C:\Program Files\Apache Software Foundation\Tomcat 8.0\lib\ojdbc6.jar" in system variables

My path variable is set as "C:\Program Files\Java\jdk1.7.0_02\bin".

My program is as follows in notepad:

<%@ page import="java.sql.*" %>
<html>
<body>
<%


Connection conn;
Statement st;
ResultSet rs;
try{
new oracle.jdbc.driver.OracleDriver();
String dbURL="jdbc:odbc:oracle:thin:@localhost:1521:XE";
String userId="system";
String pwd="moon";


conn=DriverManager.getConnection(dbURL,userId,pwd);
st=conn.createStatement();


 rs= st.executeQuery("SELECT * FROM login"); 


while(rs.next())
{
System.out.println(rs.getString(1)+""+rs.getString(2));
}


}
catch(Exception e){}






%>




</body>
</html>

I get too many errors then

eroors

org.apache.jasper.JasperException: An exception occurred processing JSP page /page2.jsp at line 14

11: String userId="system";

12: String pwd="moon";

13:

14: conn=DriverManager.getConnection(dbURL,userId,pwd);

15: st=conn.createStatement();

16:

17: rs= st.executeQuery("SELECT * FROM login");

Stacktrace:

org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)

org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:403)

org.apache.jasper.servlet.JspServlet.service(JspServlet.java:347)

javax.servlet.http.HttpServlet.service(HttpServlet.java:725)

org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

root cause

javax.servlet.ServletException: java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
     org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:905)
     org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:834)
     org.apache.jsp.page2_jsp._jspService(page2_jsp.java:102)
     org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
     javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
     org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
     org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:403)
     org.apache.jasper.servlet.JspServlet.service(JspServlet.java:347)
     javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
     org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

Nothing solved this problem.

Chanda Roy

Best Answer

  • clcarter
    clcarter Member Posts: 1,406

    >> Nothing solved this problem.

    Can't fix a problem 'till an actual problem is identified.

    >> ODBC Driver Manager ... Data source name not found

    That appears to be ODBC drivers looking for a DSN (Data Set Name). If it wants a DSN, the DSN has to be specified in the code, and the DSN has to be configured in the windows host ODBC applet. So that is at least two squirrels to get in the right tree before moving forward. A ...host:...[port:]SID|service name are some of the bits needed in a jdbc connect string, and that is in no way related to DSNs. A Whole Different Animal. If it wants a DSN that might be what needs to go in the URL bit.

    And ODBC setups can be confusing, especially if an x64 OS is in the mix- if that is the case there are two different ODBC configuration applets, one for x64 the other for x86, and if one gets as far as talking to an actual database it might toss an architecture error. Only way to fix that "problem" is *delete* the ODBC DSN and then run the correct (maybe the x86) ODBC config utility, and set up the DSN. Again.

    Chanda Roy

Answers

  • clcarter
    clcarter Member Posts: 1,406

    >> Nothing solved this problem.

    Can't fix a problem 'till an actual problem is identified.

    >> ODBC Driver Manager ... Data source name not found

    That appears to be ODBC drivers looking for a DSN (Data Set Name). If it wants a DSN, the DSN has to be specified in the code, and the DSN has to be configured in the windows host ODBC applet. So that is at least two squirrels to get in the right tree before moving forward. A ...host:...[port:]SID|service name are some of the bits needed in a jdbc connect string, and that is in no way related to DSNs. A Whole Different Animal. If it wants a DSN that might be what needs to go in the URL bit.

    And ODBC setups can be confusing, especially if an x64 OS is in the mix- if that is the case there are two different ODBC configuration applets, one for x64 the other for x86, and if one gets as far as talking to an actual database it might toss an architecture error. Only way to fix that "problem" is *delete* the ODBC DSN and then run the correct (maybe the x86) ODBC config utility, and set up the DSN. Again.

    Chanda Roy
  • Chanda Roy
    Chanda Roy Member Posts: 2
    edited Jun 1, 2014 8:13AM

    This solved my problem. I found that i had two versions of oracle uninstalled on my system: Oracle 10.2.0 and oracle 11g. I installed both of them and re-installed oracle 11g.It worked..Thankss for the answer.

    Chanda Roy
This discussion has been closed.