• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Database access with servlet

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI guys !
I trying to access database through my servlet. I am using Visual age for Java. I am using access database for which I have created a dsn on my machine.
But this the error I am getting on invoking the servlet
<b>
Error 405
An error has occured while processing request:http://localhost:8080/servlet/aetna.DBServlet
Message: HTTP method GET is not supported by this URL
Target Servlet: aetna.DBServlet
StackTrace:
--------------------------------------------------------------------------------
Root Error-1: HTTP method GET is not supported by this URL
com.ibm.servlet.engine.webapp.WebAppErrorReport: HTTP method GET is not supported by this URL
java.lang.Throwable(java.lang.String)
java.lang.Exception(java.lang.String)
javax.servlet.ServletException(java.lang.String)
com.ibm.websphere.servlet.error.ServletErrorReport(java.lang.String)
com.ibm.servlet.engine.webapp.WebAppErrorReport(java.lang.String)
void com.ibm.servlet.engine.webapp.WebAppDispatcherResponse.sendError(int, java.lang.String)
void javax.servlet.http.HttpServlet.doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
void javax.servlet.http.HttpServlet.service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
void javax.servlet.http.HttpServlet.service(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
void com.ibm.servlet.engine.webapp.StrictServletInstance.doService(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
void com.ibm.servlet.engine.webapp.StrictLifecycleServlet._service(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
void com.ibm.servlet.engine.webapp.IdleServletState.service(com.ibm.servlet.engine.webapp.StrictLifecycleServlet, javax.servlet.ServletRequest, javax.servlet.ServletResponse)
void com.ibm.servlet.engine.webapp.StrictLifecycleServlet.service(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
void com.ibm.servlet.engine.webapp.ServletInstance.service(javax.servlet.ServletRequest, javax.servlet.ServletResponse, com.ibm.servlet.engine.webapp.WebAppServletInvocationEvent)
void com.ibm.servlet.engine.webapp.ValidServletReferenceState.dispatch(com.ibm.servlet.engine.webapp.ServletInstanceReference, javax.servlet.ServletRequest, javax.servlet.ServletResponse, com.ibm.servlet.engine.webapp.WebAppServletInvocationEvent)
void com.ibm.servlet.engine.webapp.ServletInstanceReference.dispatch(javax.servlet.ServletRequest, javax.servlet.ServletResponse, com.ibm.servlet.engine.webapp.WebAppServletInvocationEvent)
void com.ibm.servlet.engine.webapp.WebAppRequestDispatcher.handleWebAppDispatch(com.ibm.servlet.engine.webapp.WebAppRequest, javax.servlet.http.HttpServletResponse, boolean)
void com.ibm.servlet.engine.webapp.WebAppRequestDispatcher.dispatch(javax.servlet.ServletRequest, javax.servlet.ServletResponse, boolean)
void com.ibm.servlet.engine.webapp.WebAppRequestDispatcher.forward(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
void com.ibm.servlet.engine.webapp.InvokerServlet.service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
void javax.servlet.http.HttpServlet.service(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
void com.ibm.servlet.engine.webapp.StrictServletInstance.doService(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
void com.ibm.servlet.engine.webapp.StrictLifecycleServlet._service(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
void com.ibm.servlet.engine.webapp.IdleServletState.service(com.ibm.servlet.engine.webapp.StrictLifecycleServlet, javax.servlet.ServletRequest, javax.servlet.ServletResponse)
void com.ibm.servlet.engine.webapp.StrictLifecycleServlet.service(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
void com.ibm.servlet.engine.webapp.ServletInstance.service(javax.servlet.ServletRequest, javax.servlet.ServletResponse, com.ibm.servlet.engine.webapp.WebAppServletInvocationEvent)
void com.ibm.servlet.engine.webapp.ValidServletReferenceState.dispatch(com.ibm.servlet.engine.webapp.ServletInstanceReference, javax.servlet.ServletRequest, javax.servlet.ServletResponse, com.ibm.servlet.engine.webapp.WebAppServletInvocationEvent)
void com.ibm.servlet.engine.webapp.ServletInstanceReference.dispatch(javax.servlet.ServletRequest, javax.servlet.ServletResponse, com.ibm.servlet.engine.webapp.WebAppServletInvocationEvent)
void com.ibm.servlet.engine.webapp.WebAppRequestDispatcher.handleWebAppDispatch(com.ibm.servlet.engine.webapp.WebAppRequest, javax.servlet.http.HttpServletResponse, boolean)
void com.ibm.servlet.engine.webapp.WebAppRequestDispatcher.dispatch(javax.servlet.ServletRequest, javax.servlet.ServletResponse, boolean)
void com.ibm.servlet.engine.webapp.WebAppRequestDispatcher.forward(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
void com.ibm.servlet.engine.srt.WebAppInvoker.handleInvocationHook(java.lang.Object)
void com.ibm.servlet.engine.invocation.CachedInvocation.handleInvocation(java.lang.Object)
void com.ibm.servlet.engine.srp.ServletRequestProcessor.dispatchByURI(java.lang.String, com.ibm.servlet.engine.srp.ISRPConnection)
void com.ibm.servlet.engine.oselistener.OSEListenerDispatcher.service(com.ibm.servlet.engine.oselistener.api.IOSEConnection)
void com.ibm.servlet.engine.http_transport.HttpTransportHandler.handleConnection(java.net.Socket)
void com.ibm.servlet.engine.http_transport.HttpTransportHandler.run()
void java.lang.Thread.run()
</b>
This is my code:
<b><i>
public void performTask(HttpServletRequest request, HttpServletResponse response) throws IOException {
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
String user="n017710";
String pwd ="190103";
String dsn = "jdbc dbc:mydsn";
response.setContentType("text/html");
PrintWriter out = response.getWriter();

try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection(dsn,user,pwd);

stmt = con.createStatement();

rs = stmt.executeQuery("Select * from employees");
out.println("<html><head><title>Employees</title></head>");
out.println("<body>");
while(rs.next()) {
out.println("<b>" + rs.getString("Name") + " " + rs.getString("password"));
}
out.println("</b></body></html>");
}catch(ClassNotFoundException e){
out.println("COuldn't load database driver " + e);
}catch(SQLException e){
out.println("SQL Exception caught: "+ e);
}finally {
try {
if(con != null)
con.close();
}catch (SQLException e){
System.out.println(e);
}
}
}
</b></i>
Waiting for replies ....
thnx Manoj
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Am I missing something here? I did not see where you are overiding the GET or POST method.

Bosun
 
Manoj Singh
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The full code is given below:
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
* Creation date: (09/06/2001 9:44:11 AM)
* @author: Manoj Singh
*/
public class DBServlet extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
performTask(request,response);

}
/**
* Process incoming requests for information
*
* @param request Object that encapsulates the request to the servlet
* @param response Object that encapsulates the response from the servlet
*/
public void performTask(HttpServletRequest request, HttpServletResponse response) throws IOException {
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
String user="n017710";
String pwd ="190103";
String dsn = "jdbc dbc:mydsn";
response.setContentType("text/html");
PrintWriter out = response.getWriter();

try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection(dsn,user,pwd);

stmt = con.createStatement();

rs = stmt.executeQuery("Select * from employees");
out.println("<html><head><title>Employees</title></head>");
out.println("<body><b>");
//while(rs.next()) {
//out.println(rs.getString("Name"));
//}
out.println("</b></body></html>");
}catch(ClassNotFoundException e){
out.println("COuldn't load database driver " + e);
}catch(SQLException e){
out.println("SQL Exception caught: "+ e);
}finally {
try {
if(con != null)
con.close();
}catch (SQLException e){
System.out.println(e);
}
}

}


}
 
Saloon Keeper
Posts: 27796
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd check the web.xml file. It looks like the server implementation's HttpServlet.doGet method may be checking for authority and finding that it's denied so it throws an exception.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic