Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet javax. servlet.Servlet Exception: Initialization failed, Unable to get DB connection
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


whoamig
javax. servlet.Servlet Exception: Initialization failed, Unable to get DB connection
4 Answer(s)      6 years ago
Posted in : JSP-Servlet



Advertisement
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
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 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
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: 1)form.html: <html> <...("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc
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
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
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
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
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
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
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 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
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
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
How to "Get data froom MySQL DB on giving a value in a tex-box in a JSP file."
How to "Get data froom MySQL DB on giving a value in a tex-box in a JSP file."  Hi, How to get data from MYSQL Database tables on giving a "text" in a text-box in a JSP file. Ex:dept table; if we give dept_no in a text-box in JSP
Connection
Connection  What is Connection
connection
connection   how to make multiple database connection using jdbc
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
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
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
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
JEE 7 JSON java.lang.NoClassDefFoundError: javax/json/Json
JEE 7 JSON java.lang.NoClassDefFoundError: javax/json/Json  Hi, While using the JSON in jee 7 based application I getting following errors...(Thread.java:724) Caused by: java.lang.NoClassDefFoundError: javax/json/Json
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
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
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
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 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
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
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
 

 

 

DMCA.com