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



Home Answers Viewqa JSP-Servlet please help me solve this problem when i am create database connection using servlecontext
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


arunnarwal
please help me solve this problem when i am create database connection using servlecontext
0 Answer(s)      2 years and 8 months ago
Posted in : JSP-Servlet


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();
    }

Advertisement
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
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
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
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
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
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
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
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 ...   ...(new BorderLayout()); //Load the pet images and create an array of indexes
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
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 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
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
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 ‚
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√Ę‚?¨‚
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
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
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 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
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
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
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
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
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
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 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√Ę‚?¨¬
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  program for when a user enter his card number, it has to create default security pin in the database
Advertisements
 

 

 

DMCA.com