• Post Reply Bookmark Topic Watch Topic
  • New Topic

connection problem from servlet to jdbc  RSS feed

 
Geeta Ravikanti
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is my Program

import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class FetchingData extends HttpServlet{
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException{
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
String connectionURL = "jdbc racle:thin:@localhost:1521:xe";
Connection connection=null;
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
connection = DriverManager.getConnection(connectionURL, "SYSTEM", "remora");
Statement st = connection.createStatement();
ResultSet rs = st.executeQuery("Select * from student1");
while(rs.next()){
pw.println("StuNo" + " " + "StuName" + "<br>");
pw.println(rs.getInt(1) + " " + rs.getString(2) + "<br>");
}
}
catch (Exception e){
pw.println(e);
}
}
}



I am doing that program in Eclipse editor and I added jar file on current Project is ojdbc14.jar ang build the path

when i am running the above code from browser i am getting exception like this

java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver

i did and run my program in correct way in my knowledge

please any one tell me where did i mistaked

ThanQ
Geeta
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The jar needs to be on the runtime classpath too. The easiest way to this in web servers is to lplace it in the WEB-INF/lib directory
 
Geeta Ravikanti
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanQ very much its working
its displaying the data in the browser
Its great
-----------------------------
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Geeta Ravikanti
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi David,


I got one problem in my program

This is my program


import java.io.*;
import java.lang.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class ServletInsert extends HttpServlet{
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException{
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
String connectionURL = "jdbc racle:thin:@localhost:1521:xe";
Connection connection;
try{
String username = request.getParameter("username");
String password = request.getParameter("password");
pw.println(username);
pw.println(password);
Class.forName("oracle.jdbc.driver.OracleDriver");
connection = DriverManager.getConnection(connectionURL, "SYSTEM", "remora");
PreparedStatement pst = connection.prepareStatement("insert into emp_info values(?,?)");
pst.setString(1,username);
pst.setString(2,password);
int i = pst.executeUpdate();
if(i!=0){
pw.println("<br>Record has been inserted");
}
else{
pw.println("failed to insert the data");
}
}
catch (Exception e){
pw.println(e);
}
}
}




SampleHtml.html




<html>

<head>
<title>New Page 1</title>
</head>

<body>

<form method="POST" action="ServletInsert">
<p>Enter Name:       <input type="text"
name="username" size="20"></p>
<p>Enter Password: <input type="text" name="password" size="20"></p>
<p>          
               
<input type="submit" value="Submit" name="B1"></p>
</form>

</body>

</html>



web.xml


<web-app>

<servlet>

<servlet-name>inserting</servlet-name>

<servlet-class>ServletInsert</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>inserting</servlet-name>

<url-pattern>/ServletInsert</url-pattern>

</servlet-mapping>

</web-app>



i set the calss path correctly,i added jar files in runtime that is web-inf/lib correctly but when i run my program its giving following error


HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Wrapper cannot find servlet class ServletInsert or a class it depends on
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:793)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:702)
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:571)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:644)
java.lang.Thread.run(Thread.java:595)


root cause

java.lang.ClassNotFoundException: ServletInsert
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1340)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1189)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:793)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:702)
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:571)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:644)
java.lang.Thread.run(Thread.java:595)


note The full stack trace of the root cause is available in the Apache Tomcat/5.0.25 logs.


--------------------------------------------------------------------------------

Apache Tomcat/5.0.25


i did every thing correctly with my knowledge
can you tell me where did i mistaked how can i rectify error in my program
plzzzz-----------
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
new questions should be asked in a new thread, not the same thread.

Can you move your servlet into a package and see if that fixes it?

We had a previous discussion where I suggested the package might matter and suri suggested it qouldn't, but please humour me and try it out.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, please check the tomcat logs for any other errors that may indicate that the class was found but failed to load.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!