please help me solve this problem when i am create database connection using servlecontext

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:
please help me solve this problem when i am create database connection using servlecontext
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
I am having problem with configuring Hibernate sessionfactory. Please Help
I am having problem with configuring Hibernate sessionfactory. Please Help  Sir, I am having problem with configuring Hibernate sessionfactory.. I was using the old version of Hibernate before now I am using Hibernate 4
Advertisements
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
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
i am getting the problem when i am downloading the pdf file from oracle 10g database - Struts
i am getting the problem when i am downloading the pdf file from oracle 10g... but it is not downloading .Please help to me.i am getting the below error when downloading... into datbase and download the pdf file from database. but when i created the pdf file
how can create pop() method in this program ,Or how can delete image in it when i press pop button in runtime ??? please help me ...
how can create pop() method in this program ,Or how can delete image in it when i press pop button in runtime ??? please help me ...   ...) { images[i].setDescription(aray[i]); } } //Create
Begineer Help Help Please Thanks A million ) I am using Jcreator
Begineer Help Help Please Thanks A million ) I am using Jcreator  ...(Arrays.toString(Year)); The problem of this coding is that it will show null values before...: $ 1.00 Retained Earnings: $ 2.00 I don't know how to sort the array
this is my javascript code and i am not understanding the mistake in this,please help me?
this is my javascript code and i am not understanding the mistake in this,please help me?  <html> <h2>Form Validation</h2>...; if((nn1.value==null)||(nn1.value=="")){ alert("Please Enter
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
please help me to overcome this problem
please help me to overcome this problem  how to make it easy to write java code. can u please give me suggestions
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... main(String[] args) { char arr[] = { 'a', 'e', 'i', 'o', 'u' }; String
I want to update the multiple values of database depending on checkbox..? Please help me out..
I want to update the multiple values of database depending on checkbox..? Please help me out..   Hi .. I want to Update the multiple values of database using checkboxes and want to set the session for selected checkboxes
autocomplete(): Spring mvc with jquery: I am not getting correct value in the text filed. Please help me
autocomplete(): Spring mvc with jquery: I am not getting correct value in the text filed. Please help me   Hi have develop the jsp to populate... filed?. Please help me Thanks
Please help me to create this coding for pizza order application using a handheld computer.....
Please help me to create this coding for pizza order application using... in the kitchen which displays the orders to be cooked. anybody please help me... software which will allow waiters to take orders from tables using a hand held
CAN ANYONE SOLVE THIS FOR ME. URGENT HELP NEEDED. PLEASE HELP
CAN ANYONE SOLVE THIS FOR ME. URGENT HELP NEEDED. PLEASE HELP   The Task Write a class whose objects will represent students... marks. Create a new project. Then create a new class called â
Please help me to solve these programs in Python - Java Beginners
Please help me to solve these programs in Python  1. Write a program... * ** *** **** 2. Write a function that given the string ?original? create a new string..., public class PrintExamp{ public static void main(String[] args){ int i=1
CAN ANYONE SOLVE THIS FOR ME. URGENT HELP NEEDED. PLEASE HELP
CAN ANYONE SOLVE THIS FOR ME. URGENT HELP NEEDED. PLEASE HELP   Write...?¢t compile then you wonââ?¬â?¢t earn any marks. Create a new project. Then create a new class called ââ?¬Ë?Studentââ?¬â
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
How can I access databse through JSP. I am using postgresql-8.4.4-1-windows as database and jboss-4.0.5.GA as server.
netbeans-6.1-ml-windows.How can I set up connection to database? Please help me...How can I access databse through JSP. I am using postgresql-8.4.4-1-windows as database and jboss-4.0.5.GA as server.  I am using postgresql-8.4.4-1
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
i have problem with this query... please tell me the resolution if this .........
i have problem with this query... please tell me the resolution if this .........  select length(ename)||' charecters exist in '||initcap(ename)||'s name' as "names and length" from emp
i have problem with this query... please tell me the resolution if this .........
i have problem with this query... please tell me the resolution if this .........  select initcap(ename),job from emp where substr(job,4,length(job,4,3)))='age
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
I really need help with this assignment question Please help me out Please
I really need help with this assignment question Please help me out Please ... searches on the database. Using your IDE (NetBeans or Eclipse), you should develop... created in class. Create a table in the database named ââ?¬Å?LaptopPoolââ?¬Â
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
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 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
Why the null values are stored in Database when I am sending proper values?
Why the null values are stored in Database when I am sending proper values... I am also sending the name, Rate, Dimension to the Database through the text... values are stored in the Database. Please guide me. Ask any more details
plz help me out with this problem...please write the program for me.thanxxxxx
plz help me out with this problem...please write the program for me.thanxxxxx  Write a program that will print out a hydro bill. The bill will be formatted as the example on the next page. The following information
plz help me out with this problem...please write the program for me.thanxxxxx
plz help me out with this problem...please write the program for me.thanxxxxx  Write a program that will print out a hydro bill. The bill will be formatted as the example on the next page. The following information
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
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
inheritance....please help me friends...!!!... this is important project that i have to do it..
inheritance....please help me friends...!!!... this is important project that i have to do it..   Point ................. #x : int #y : int... program that - Create one Circle object known as objectCircle with radius is 2.7, x
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 netbeans
plz 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
i have a problem to do this question...pls help me..
i have a problem to do this question...pls help me..  Write a program... reversedNumber = 0; for (int i = 0; i <= num; i...; reversedNumber = reversedNumber * 10 + r; i = 0
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
I need help on my Java code.... please please help me out!?
I need help on my Java code.... please please help me out!?  Well my... the anagram on screen or the output file! Please show me whats wrong. Thanks i... the input file and create an output.txt file with the anagram for the words
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
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
to all Experts.. please help me. im using a Jcreator. - Java Beginners
to all Experts.. please help me. im using a Jcreator.  3. Write a program that asks the user to enter a word. The program will then repeat word...=word.length(); System.out.println(); for(int i=0;i
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 here
please 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

Ads