Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Problem while trying to run a jdbc using servlet on jboss
Problem while trying to run a jdbc using servlet on jboss [message #1114710] Mon, 23 September 2013 05:22 Go to next message
Lavanya M is currently offline Lavanya MFriend
Messages: 1
Registered: September 2013
Junior Member
I wrote a servlet program to access data from my database. When run as a simple jdbc application, its working well...but when trying to run on jboss...its being an issue!! Can anyone please help me with this??? Thank you!!

Here's my code and follows is the console i am getting:

package com.vacation.mypackage;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* Servlet implementation class SampleServlet
*/
@WebServlet("/SampleServlet")
public class SampleServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
* @see HttpServlet#HttpServlet()
*/
public SampleServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Connection conn = null;
Statement stmt = null;

// Set response content type
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String title = "Database Result";
String docType =
"<!doctype html public \"-//w3c//dtd html 4.0 " +
"transitional//en\">\n";
out.println(docType +
"<html>\n" + "<head><title>" + title + "</title></head>\n" +
"<body bgcolor=\"#f0f0f0\">\n" +
"<h1 align=\"center\">" + title + "</h1>\n");

try{
out.println("hi before Class.forName");
Class.forName("com.mysql.jdbc.Driver");
out.println("hi");

conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/Emp","root","1234");


stmt = conn.createStatement();
String qry;
qry = "SELECT emp_id, fname, dept_id, work_location_id FROM Employee";
out.println(qry);
ResultSet rs = stmt.executeQuery(qry);


while(rs.next()){
int emp_id = rs.getInt("emp_id");
String fname = rs.getString("fname");
int dept_id = rs.getInt("dept_id");
int work_location_id = rs.getInt("work_location_id");

out.println("Employee ID: " + emp_id + "<br/>");
out.println("First Name: " + fname + "<br/>");
out.println("Department ID: " + dept_id + "<br/>");
out.println("Work Location ID:" + work_location_id + "<br/>");
}
out.println("</body></html>");

out.println("THE END");

rs.close();
stmt.close();
conn.close();
}catch(SQLException se){
se.printStackTrace();
}catch(Exception e){
e.printStackTrace();
}finally{
try{
if(stmt!=null)
stmt.close();
}catch(SQLException se2){
se2.printStackTrace();
}
try{
if(conn!=null)
conn.close();
}catch(SQLException se){
se.printStackTrace();
}
}
}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}

}

10:40:49,263 INFO [org.jboss.web.tomcat.service.deployers.TomcatDeployment] deploy, ctxPath=/VacationTrackingSystem
10:40:50,276 ERROR [STDERR] java.lang.ClassNotFoundException: com.mysql.jdbc.Driver from BaseClassLoader@1671cbc{vfs:///D:/Lavanya/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_6.x_Runtime_Server1378986723871/deploy/VacationTrackingSystem.war}

10:40:50,276 ERROR [STDERR] at org.jboss.classloader.spi.base.BaseClassLoader.loadClass(BaseClassLoader.java:480)

10:40:50,276 ERROR [STDERR] at java.lang.ClassLoader.loadClass(ClassLoader.java:251)

10:40:50,276 ERROR [STDERR] at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

10:40:50,276 ERROR [STDERR] at java.lang.Class.forName0(Native Method)

10:40:50,276 ERROR [STDERR] at java.lang.Class.forName(Class.java:169)

10:40:50,276 ERROR [STDERR] at com.vacation.mypackage.SampleServlet.doGet(SampleServlet.java:52)

10:40:50,323 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:734)

10:40:50,323 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)

10:40:50,323 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:324)

10:40:50,323 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242)

10:40:50,338 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)

10:40:50,338 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)

10:40:50,338 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:181)

10:40:50,338 ERROR [STDERR] at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.event(CatalinaContext.java:285)

10:40:50,338 ERROR [STDERR] at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.invoke(CatalinaContext.java:261)

10:40:50,338 ERROR [STDERR] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:88)

10:40:50,338 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:100)

10:40:50,338 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:159)

10:40:50,338 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)

10:40:50,338 ERROR [STDERR] at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)

10:40:50,338 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

10:40:50,338 ERROR [STDERR] at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53)

10:40:50,338 ERROR [STDERR] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362)

10:40:50,338 ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)

10:40:50,338 ERROR [STDERR] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:654)

10:40:50,338 ERROR [STDERR] at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951)

10:40:50,338 ERROR [STDERR] at java.lang.Thread.run(Thread.java:619)

An early answer is really appreciated..thanks!!
Re: Problem while trying to run a jdbc using servlet on jboss [message #1114930 is a reply to message #1114710] Mon, 23 September 2013 12:26 Go to previous message
Kunal Ghosh is currently offline Kunal GhoshFriend
Messages: 5
Registered: August 2013
Junior Member
Please check you have added the mysql jar file.
Previous Topic:[Galileo Java] Can't create new class
Next Topic:lowResourcesConnections attribut doesn't work with jetty8.1.11
Goto Forum:
  


Current Time: Sun Mar 07 21:12:30 GMT 2021

Powered by FUDForum. Page generated in 0.03157 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top