javax. servlet.Servlet Exception: Initialization failed, Unable to get DB connection

javax. servlet.Servlet Exception: Initialization failed, Unable to get DB connection

View Answers

October 31, 2008 at 4:54 PM

Hi friend,

<html>

<head>
<title>login form application</title>
</head>

<body>
<center><h1>XYZ Company Ltd.</h1></center>
<table border="1" width="100%" height="100%">
<tr>
<td width="15%" valign="top" align="center">
<br/><a href="Login.html">Login</a><br/>
<br/><a href="Register.html">Register</a><br/>
</td>
<td valign="top" align="center"><br/>
<form method="POST" action="">

<h2 align="center"><font color="black">Login Application</font></h2>
<table border="0" width="100%" cellspacing="0" callpadding="0">
<tr>
<td width="50%" align="right"><b><font color="black">User Name:</b></font></td>
<td width="50%"><input type="text" name="uname" size="20"/> </td>
</tr>
<tr>
<td width="50%" align="right"><b><font color="black">Password:</b></font></td>
<td width="50%"><input type="password" name="pass" size="20"></td>
</tr>
</table>
<p><center><input type="submit" value="Submit" name="submit">
<input type="reset" value="Reset" name="reset"></p></center>

</form>
</td>
</tr>
</table>

</body>

</html>

October 31, 2008 at 5:13 PM

Hi friend,


Home.html

<html><body>
<center><h1>XYZ Company Ltd.</h1></center>
<table border="1" width="100%" height="100%">
<tr>
<td width="15%" valign="top" align="center">
<br/><a href="Login.html">Login</a><br/>
<br/><a href="Register.html">Register</a><br/>
</td>
<td valign="top" align="center"><br/>
Welcome to xyz.com
</td>
</tr>
</table>
</body></html>

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

Login form

<html>

<head>
<title>login form application</title>
</head>

<body>
<center><h1>XYZ Company Ltd.</h1></center>
<table border="1" width="100%" height="100%">
<tr>
<td width="15%" valign="top" align="center">
<br/><a href="Login.html">Login</a><br/>
<br/><a href="Register.html">Register</a><br/>
</td>
<td valign="top" align="center"><br/>
<form method="POST" action="loginServlet">

<h2 align="center"><font color="black">Login Application</font></h2>
<table border="0" width="100%" cellspacing="0" callpadding="0">
<tr>
<td width="50%" align="right"><b><font color="black">User Name:</b></font></td>
<td width="50%"><input type="text" name="uname" size="20"/> </td>
</tr>
<tr>
<td width="50%" align="right"><b><font color="black">Password:</b></font></td>
<td width="50%"><input type="password" name="pass" size="20"></td>
</tr>
</table>
<p><center><input type="submit" value="Submit" name="submit">
<input type="reset" value="Reset" name="reset"></p></center>

</form>
</td>
</tr>
</table>

</body>

</html>

October 31, 2008 at 5:15 PM

login action.


package javacode;

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


public class loginServlet extends GenericServlet {

private Connection con;
private PreparedStatement ps=null;

public void init() throws ServletException {
System.out.println("In init");
try {
ServletContext ctxt=getServletContext();
//Getting the Driver class name from context parameter
String driverClassName=ctxt.getInitParameter("driverClassName");
Class.forName(driverClassName);
//Getting the JDBC URL from context parameter
String url=ctxt.getInitParameter("url");

//Getting the DB Username, password & sqlstatement from servlet init parameter
String dbuser=getInitParameter("dbuser");
String dbpass=getInitParameter("dbpass");
String sqlst=getInitParameter("sqlstatement");

con=DriverManager.getConnection(url, dbuser, dbpass);
ps=con.prepareStatement(sqlst);
}//try
catch(Exception e){
e.printStackTrace();
throw new ServletException("Initialization failed, Unable to get DB connection");
}//catch
}//init

public void service (ServletRequest req, ServletResponse res) throws ServletException, IOException {

System.out.println("In service");

res.setContentType("text/html");
PrintWriter out=res.getWriter();
try {

String uname=req.getParameter("uname");
System.out.println("username>>>>>>>>>>>>: " + uname);
String pass= req.getParameter("pass");
System.out.println("pass>>>>>>>>>> :" + pass);

if (uname==null||uname.equals("")||pass==null||pass.equals("")) {

out.println("<html><body><center>");
out.println("<li><i>User Name and Password cannot be empty</i></li><br/>");
out.println("<li><i>We cannot log you into your account at this time. Please try again later</i>");
out.println("</center></body></html>");
return;
}//if

ps.setString(1,uname);
ps.setString(2,pass);
ResultSet rs=ps.executeQuery();

if (rs.next()){
out.println("<html><body>");
out.println("<center><h1>XYZ Company Ltd.</h1></center>");
out.println("<table border='1' width='100%' height='100%'>");
out.println("<tr>");
out.println("<td width='15%' valign='top' align='center'>");
out.println("<br/><a href='Login.html'>Login</a><br/>");
out.println("<br/><a href='Register.html'>Register</a>");
out.println("</td>");
out.println("<td valign='top' align='center'><br/>");
out.println("<h3>Welcome, "+uname+"</h3><br/>");
out.println("<h2>Enjoy browsing the Site</h2>");
out.println("</td></tr></table>");
out.println("</body></html>");
}
else{
out.println("<html><body><center>");
out.println("Given username and password are incorrect<br/>");
out.println("<li><i>We cannot log you into your account at this time. Please try again later</i>");
out.println("</center></body></html>");
}
}//try
catch(Exception e){
out.println("<html><body><center>");
out.println("<h2>Unable to the process the request try after some time</h2>");
out.println("</center></body></html>");
}//catch
}//service

public void destroy () {
System.out.println("In destroy");
try {
con.close();
}
catch(Exception e){
System.out.println("error : " + e);
}
}//destroy
}//class


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

October 31, 2008 at 5:18 PM

if you have any problem then check database connection code web.xml.


Visit for more information.


http://www.roseindia.net/jsp/jsp-authentication.shtml


Thanks.










Related Tutorials/Questions & Answers:
javax. servlet.Servlet Exception: Initialization failed, Unable to get DB connection - JSP-Servlet
javax. servlet.Servlet Exception: Initialization failed, Unable to get DB... ServletException("Initialization failed, Unable to get DB connection... { private Connection con; private PreparedStatement ps=null; public void init
Server DB connection - JDBC
get it to work. If you have any sample code for getting connection please...Server DB connection  Hello Guys I want to connect two databases at the same time but it looks like the java is only picking up the second database
Advertisements
Unable the get SubFolder Direcotry in Java?:-
Unable the get SubFolder Direcotry in Java?:-   Unable the get SubFolder Direcotry in Java?:- try { String st1 = "C:\TestFolder; // Main Folder URL File folder = new File(st1); File[] listOfFiles = folder.listFiles(); for (File
unable to get datas from oracle database
unable to get datas from oracle database  Dear Sir, I am again struck in my project.. i want to display data from oracle database but i get...; <%try { Connection con=null; Class.forName
ModuleNotFoundError: No module named 'django-db-connection-retrier'
ModuleNotFoundError: No module named 'django-db-connection-retrier'  ...: No module named 'django-db-connection-retrier' How to remove the ModuleNotFoundError: No module named 'django-db-connection-retrier' error
ModuleNotFoundError: No module named 'pwx-db-connection'
ModuleNotFoundError: No module named 'pwx-db-connection'  Hi, My... named 'pwx-db-connection' How to remove the ModuleNotFoundError: No module named 'pwx-db-connection' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'pwx-db-connection'
ModuleNotFoundError: No module named 'pwx-db-connection'  Hi, My... named 'pwx-db-connection' How to remove the ModuleNotFoundError: No module named 'pwx-db-connection' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'django-db-connection-pool'
ModuleNotFoundError: No module named 'django-db-connection-pool'  Hi...: No module named 'django-db-connection-pool' How to remove the ModuleNotFoundError: No module named 'django-db-connection-pool' error? Thanks  
ModuleNotFoundError: No module named 'django-db-connection-retrier'
ModuleNotFoundError: No module named 'django-db-connection-retrier'  ...: No module named 'django-db-connection-retrier' How to remove the ModuleNotFoundError: No module named 'django-db-connection-retrier' error
Struts2...problem in JSP..unable to get the values for menuTitle!!!
Struts2...problem in JSP..unable to get the values for menuTitle!!!  ... Connection getConnection(){ Connection con=null; try{ Class.forName...; fetch(){ try{ System.out.println("\nInside DAO fetch... "); Connection con
Todd oracle DB connection through PHP
Todd oracle DB connection through PHP  Can u please explain how to connect Todd oracle DB using PHP & What are the setups we need to perform? Thanks
Unable to get data from class - Development process
Unable to get data from class  I get this code from the internet which read from comm port of the computer & modify is as below:- package COM...); initComponents(); // status bar initialization - mess
code for jsp to db connection using jdbc
code for jsp to db connection using jdbc  please send me the code   Hi Friend, Try the following code:ADS_TO_REPLACE_1 1)form.html: <...("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con
unable to get value returned from javascript variable in page
unable to get value returned from javascript variable in page  Hi, I have 3 pages....i wrote a js function to get the value of radio button from one jsp page..what i want is to store the value returned from the js function
Artifacts of javax
List of Artifacts of javax maven depenency
Problem to get connection from DAO class to JDBC
Problem to get connection from DAO class to JDBC  package controller... ConnectionProvider { private static Connection con=null; //static Connection..."); }catch(Exception e){} } public static Connection getCon(){ return con
ModuleNotFoundError: No module named 'javax'
ModuleNotFoundError: No module named 'javax'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'javax' How to remove the ModuleNotFoundError: No module named 'javax'
ModuleNotFoundError: No module named 'javax'
ModuleNotFoundError: No module named 'javax'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'javax' How to remove the ModuleNotFoundError: No module named 'javax'
Access URL Failed!?
Access URL Failed!?  Hi, May i know how to convert my domain name into IP address? becuase i working on J2ME but don't know why the my application unable to access the URL. "connector.open("http://886089.com/datetime.asp")". I
ModuleNotFoundError: No module named 'aws-get-vpn-connection-info'
ModuleNotFoundError: No module named 'aws-get-vpn-connection-info'  ...: No module named 'aws-get-vpn-connection-info' How to remove the ModuleNotFoundError: No module named 'aws-get-vpn-connection-info' error? Thanks
connection retry in java
connection retry in java  How to retry the connection automatically once it get disconnect..?   Connection connection = null; while...("Connecting failed, retrying..."); } } return connection
connection of java file to excel file and put data from excel file into oracle db
connection of java file to excel file and put data from excel file into oracle db  how to create button on excel sheet using java swing and how we... as wellas to oracle db to insert excel data into database
javax - JSP-Servlet
javax  Where can i download javax.* package. If anyone know the exact url please send me.  HI, Visit for more information. http://www.roseindia.net/servlets/introductiontoconfigrationservlet.shtml Thanks
Connection
Connection  What is Connection
Version of javax>javaee-api dependency
connection
connection   how to make multiple database connection using jdbc
How to get data from DB in to Text box by using Jsp & Ajax
How to get data from DB in to Text box by using Jsp & Ajax   I want to get the data from database in to text box in a jsp page by using Ajax. If I enter the letter A in the textbox it should show only those values which starts
Failed Client-Socket Communication
Failed Client-Socket Communication  I hve written a server program... in the client. I hve to get 16 values to be echoed. I hve created a string and all the values are added to this string. When I pass the string to the server, it doesn get
Lookup failed in SessionBean
Lookup failed in SessionBean  Hi. I've downloaded session bean example which invokes session beans. File was named example3. So I wanted to make... directories but I get Exception in method "Object objref = ctx.lookup("ejb/test
unable to connect database in java
unable to connect database in java  Hello Everyone! i was trying to connect database with my application by using java but i am unable to connect... button. 4)Then give Data Source Name and click ok button. 5)Your DSN will get
connection
the connection with the available port on the host machine: import java.net.... the connection was not established. Predict the output of the preceding code. Explain why the connection cannot be established
Unable to compile Servlet
Unable to compile Servlet  First I installed the tomcat server in C:\apache-tomcat-6.0.14 directory. Then I created a system variable CATALINA_HOME... But the compilation failed totally
open() /etc/nginx/nginx.conf failed
-VirtualBox nginx[2880]: nginx: [emerg] open() "/etc/nginx/nginx.conf" failed (2...: configuration file /etc/nginx/nginx.conf test failed Apr 04 17:29:34 bugs-VirtualBox...:29:34 bugs-VirtualBox systemd[1]: nginx.service: Failed with result 'exit-code
Failed to Call Procedure
Failed to Call Procedure  You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'sum(case when c.result = '1' then 1 else 0 end ) as Pass_total, sum
unable to execute the examples
unable to execute the examples  unable to execute the examples given for struts,ejb,or spring tutorials.Please help I am a beginner
Unable to store the image into database
Unable to store the image into database  Hello, I have created below..."); System.out.println("Connection loaded"); Connection con...("Connection created"); String ll=request.getParameter("user_file"); String
unable to open the service tomcat5
unable to open the service tomcat5  While trying to run tomcat server getting "unable to open the service tomcat5" error after installed tomcat
connection
connection   How to get connected to my database using jsp   Please visit the following links: http://www.roseindia.net/jsp/connectjspwith_mysql.shtml http://www.roseindia.net/jsp/displaydatafrom_database1.shtml http
Version of javax>javaee-endorsed-api dependency
Version of javax>javaee-web-api dependency
Unable to use JMXMP with Knopflerfish?
Unable to use JMXMP with Knopflerfish?  I have a bundle which runs properly with Eclipse, then I generate the jar file and try to use it with Knopflerfish, then I get the following exception java.net.MalformedURLException
db
= "jdbc:oracle:thin:@localhost:1521:XE"; Connection connection = null...; Class.forName("oracle.jdbc.driver.OracleDriver").newInstance(); connection
db
= "jdbc:oracle:thin:@localhost:1521:XE"; Connection connection = null...; Class.forName("oracle.jdbc.driver.OracleDriver").newInstance(); connection
java.lang.NoClassDefFoundError: javax/transaction/UserTransaction????? - Struts
java.lang.NoClassDefFoundError: javax/transaction/UserTransaction?????  Hi EveryOne, I am using the Quartz as scheduler in my project .If i am... as java.lang.NoClassDefFoundError: javax/transaction/UserTransaction
javax servlet error - JSP-Servlet
javax servlet error  Hi, Can someone help me to figure out, why im getting the error below, when im trying to enter my web page.. Please help me...: javax/servlet/jsp/JspFactory (Unsupported major.minor version 49.0
E: Unable to locate package oracle-java8-installer
E: Unable to locate package oracle-java8-installer  Hi, I am trying to install with following command on Ubuntu 17.04: sudo apt-get install oracle-java8-installer It gives following error: E: Unable to locate package
E: Unable to locate package oracle-java8-installer
E: Unable to locate package oracle-java8-installer  Hi, I am trying to install with following command on Ubuntu 17.04: sudo apt-get install oracle-java8-installer It gives following error: E: Unable to locate package
unable to insert data into database
unable to insert data into database    hello.i have a problem in inserting data into database.i have used two prepared statement.one for retrieving...(int pid,int ptime,int rtime,String workdone,String ename) { Connection
unable to insert data into database
unable to insert data into database    hello.i have a problem in inserting data into database.i have used two prepared statement.one for retrieving...(int pid,int ptime,int rtime,String workdone,String ename) { Connection
unable to insert data into database
unable to insert data into database    hello.i have a problem in inserting data into database.i have used two prepared statement.one for retrieving...(int pid,int ptime,int rtime,String workdone,String ename) { Connection

Ads