please help me solve this problem when i am create database connection using servlecontext
hi...
I have create a database connection using servletcontext . in this code when i login first time it will exceute sucessfully but when i use again the same page it will throw sql exception but i don't understand what is the problem ....
the code are as follows.
the servlet context classss.
public void contextInitialized(ServletContextEvent arg0) {
ServletContext sc = arg0.getServletContext();
String url=sc.getInitParameter("url");
String user=sc.getInitParameter("username");
String pass= sc.getInitParameter("password");
database db = new database(url, user, pass);
System.out.println("hello*******************************************************************************");
sc.setAttribute("db", db);
}
//database connection class
Connection con = null;
public database(String url,String user, String pass) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
this.con = DriverManager.getConnection(url,user,pass);
} catch (Exception e) {
// TODO Auto-generated catch block
System.out.println("sorry********************"+e);
e.printStackTrace();
}
}
//the servlet class.
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String user= request.getParameter("username");
String password= request.getParameter("password");
database db = (database)getServletContext().getAttribute("db");
try {
PreparedStatement ps = db.con.prepareStatement("select * from admintable where vusername=? and vpassword=?");
ps.setString(1,user);
ps.setString(2, password);
ResultSet rs= ps.executeQuery();
if(rs.next())
{
System.out.println("************login sucessfully*******************");
PrintWriter out=response.getWriter();
out.println("hello arunnarwal");
db.con.close();
}
} catch (Exception e) {
// TODO Auto-generated catch block
System.out.println("sorry**************************");
e.printStackTrace();
}
View Answers
Ads
Related Tutorials/Questions & Answers:
Advertisements
help me to solve this problem..
help me to
solve this
problem.. Given below is a class definition for Book. Type and compile the class, and answer the following questions:
class... and then
create an array name myLibrary of type Book with size n.
Using loop,
create n
Please Help To Solve My Problem
Please Help To
Solve My Problem PHP
I Have 6 Textbox and 1 ok... With B Team
when A Team Play With B Team Again Then Generate Error.
I Am Solve...)
When I Add This Six Team Name In Six Text Box Then
I Will Click On Ok Button
please help me to this problem..
please help me to this
problem..
i wrote a program like keyboard... inside the JTextField) but
i want to make this program to let
me write where
i clicked (i.e allows
me to write any thing at the field where
i clicked
problem in writing coding. Please help me.
problem in writing coding.
Please help me. Hi sir, my name is Logeswaran.
I have
problem in writing JSP coding for my university assigments... like? I'm really stuck on this.
Please help me.
By the way, I'm
using Access
i need help to solve this problem
i need
help to
solve this problem Write a stack class ArrayStack.java implements PureStack interface that reads in strings from standard input.... H and
I join the queue
h. G leaves the queue
i. H and
I leave the queue
please help me to solve this question about array
please help me to
solve this question about array write a program thatt stores vowels (a,e,
i,o and u)in an array. Ask the user to enter any...[] args) {
char arr[] = { 'a', 'e', '
i', 'o', 'u' };
String brr;
boolean
how to solve an internet connection problem
how to
solve an internet
connection problem
when i run my application it give
me this error:
Exception in thread "AWT-EventQueue-0" java.lang.UnsupportedOperationException: Not yet implemented
the
problem is that
i don`t know
please help me
please help me Dear sir,
I have a
problem. How to write JSP coding... before. This name list should get from the
database.
Please help me.
By the way, I'm
using access
database and jsp code.
Thank you
Please help me
Please help me program for
when a user enter his card number, it has to
create default security pin in the
database
help me to solve this question...
help me to
solve this question... Given below is a class definition for Book. Type and compile the class, and answer the following questions... and then
create an array name myLibrary of type Book with size n.
Using loop,
create n
please help me.
please help me.
I have a jsp page under that
i add a list box under
i get the countries through my
database.
so how can
i do
help me to solve this question
help me to
solve this question Write a program that inputs a series of integers into an array. The numbers are in the range 0 to 100.
Calculate and display :
a) The Largest number
b) The Smallest Number
c)The sum of the numbers
help me to solve this question
help me to
solve this question
A user needs to key in data... 2009/2010 1
STIW3023
Database 2010/2011 2
b. Course code ââ?¬â... Data Structure
The message must be displayed
when the searched data does
please help me in these prog
please help me in these prog
create 2 jdbc programs including awt
create 2 jdbc programs including swing
create 2 jdbc programs including command line argument
create 2 jdbc programs including io class
4 jdbc prog
using
ajax code please help to solve this........
null;
}
please help me
when i am running this it show an error...ajax code
please help to
solve this. in this
i am trying to get data... and use ajax onchange but
when i am trying to do so it show some error