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
Related Tutorials/Questions & Answers:
Advertisements
Please Help To Solve My ProblemPlease 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
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 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 problemi 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 arrayplease 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... main(String[] args) {
char arr[] = { 'a', 'e', '
i', 'o', 'u' };
String
how to solve an internet connection problemhow 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 meplease 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.
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
Please help mePlease help me program for
when a user enter his card number, it has to
create default security pin in the
database Please help me.Please help me. Hi
i am trinath in below there is a url.In that url there is a code of edit a jsp page.I understand that code but only one thing
i not get it i.e; What is the work of "id".and what is the data type of id?
http
please help me.please help me.
Please send
me a code of template in opencms and its procedure.so
i can implement the code.
Thanks
trinath
help me to solve this questionhelp 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 questionhelp 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
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
urgent...pleAse help me.....please!urgent...
pleAse help me.....
please!
please help me urgent! how can
i do dictionary with the use of array code in java, where
i will type the word then the corresponding meaning for that word will appear...thanks
please help me.please help me.
I have three table in mysql,and
i hava
create a excel sheet and add this sheet.but my question is in every sheet
i can display one one table result.how can
i do
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
plz help me to create gui using Java netbeansplz
help me to
create gui
using Java netbeans Hi,
I am unable to fetch a particular data from DB.I
am using netbeans for creating GUI. If
I want....
I am unable to fetch the particular data. Plz
help me
Hi Friend
Please help me out Please help me out
Description* You are hired to develop a laptop... as well as perform searches on the
database.
Using your IDE (NetBeans... the sheridancollege
database we created in class.
Create a table in the
database named
help me please help me please Hello
I want helping for this question ,
Please
Write a program that reads some friends� names, stores them in an array, and then prints out on the screen all friends who start by a particular letter
please help me in these progplease 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 please help me.please help me. How to read a properties file in java with a suitable example.
Please send
me.
Thanks
Trinath
Please visit the following link:
Java read properties file
Please help me urgent...........Please help me urgent........... For what kind of a
problem would use a Tree Set and not a Tree Map
For what kind of a
problem would use a Tree Map and not a Tree Set
Hello Friend,ADS_TO_REPLACE_1
If you want
please help me.please help me.
Please send
me the validation of this below link.
the link is http://www.roseindia.net/answers/viewqa/JSP-Servlet/9584-JSP-Servlet-Search-and-Edit.html
Thanks
Trinath
please help me hereplease help me here
please show
me how can this show the right output that
i need
please continue doing this program
using only if else and do while
please please"
here is the
problem
Automatic Teller Machine [B] Balance [D