unable to retrive the data from mysql using servlet using jdbc driver

Ads

 
 

Share on Google+Share on Google+

Ajay Bhushan.B
unable to retrive the data from mysql using servlet using jdbc driver
1 Answer(s)      5 years and 7 months ago
Posted in : JDBC

Hi, i have a servlet program..to verify the login and redirect to correct html page on verification. public class LoginServlet extends HttpServlet implements javax.servlet.Servlet {

 public void doPost (HttpServletRequest request, HttpServletResponse response) 
 throws ServletException,IOException
 {
    // Get the requested name and the output writer. 
    PrintWriter out = response.getWriter (); 
    String username = request.getParameter("UserName");
    String password = request.getParameter("Password");

    //Used to instantiate a connection
    Connection con = null;
    String url = "jdbc:mysql://localhost:3306/";
    String dbName = "rapax";
    String driver = "com.mysql.jdbc.Driver";
    String userName = "root"; 
    String password1 = "ajay12";
    Statement stmt = null;
    ResultSet rs = null;
    try 
    {   
        try
        {
              Class.forName(driver).newInstance();
        }
        catch(InstantiationException e)
        {
        }
        catch(IllegalAccessException e)
        {
        }
        con = DriverManager.getConnection((new

StringBuilder()).append(url).append(dbName).toString(),userName,password1); System.out.println("Connected to the database"); stmt = con.createStatement(); rs = stmt.executeQuery("SELECT * FROM login where

username="+username+" and password="+password); // displaying records if(rs.next()) { String uname=rs.getObject(1).toString(); String pwd=rs.getObject(2).toString();

response.sendRedirect("http://localhost:8080/sessionAction.html"); }
else { out.println("\n\nInvalid Login\n"); rs.close(); response.sendRedirect("http://localhost:8080/login.html"); } // throw new IOException(new IOException("Error")); }

    catch (SQLException e) 
    {

    } 
    catch (ClassNotFoundException e) {

    } 

    finally 
            { 
        try 
              {        


                                   if(rs!=null)
                         {

                       try{

                           rs.close();
                                }
                                catch(NullPointerException e)
                {
                                }
                         }
            rs = null;
                            if(stmt!=null)
                            {
                              try
                              { 
               stmt.close();
                              }
                              catch(SQLException e)
                              {
                              }
                             }
                             stmt = null;
                            if(con!=null)
                            {
                             try
                             {
                   con.close(); 
                             }
                             catch(NullPointerException e) 
                             {
                             }
                            }


            con = null;
        }
         catch (SQLException e)
                     {

                 }
        out.close();
    }
}
public void doGet(HttpServletRequest request,HttpServletResponse response) throws   

  ServletException,IOException
    {
                doPost(request,response);
    }

}

.i am unable to redirect..here is the code..pls help me THANK YOU

Ads
View Answers

October 25, 2011 at 12:38 PM


Please visit the following link:

http://www.roseindia.net/jsp/loginbean.shtml


Ads









Related Tutorials/Questions & Answers:
unable to retrive the data from mysql using servlet using jdbc driver
unable to retrive the data from mysql using servlet using jdbc driver  Hi, i have a servlet program..to verify the login and redirect to correct... Connection con = null; String url = "jdbc:mysql://localhost:3306
Retrive the data from the table in data base using jdbc
Retrive the data from the table in data base using jdbc  Retrive the data from the table in data base using jdbc   JDBC Tutorials
Advertisements
retrive the employee details with image from mysql database using jsp servlet
retrive the employee details with image from mysql database using jsp servlet  im doing the web project to retrive the employee profile which i stored in the database using jsp servlet then want to show the result in the next jsp
Request URl using Retrive data from dtabase
Request URl using Retrive data from dtabase  Using With GWT the user can create an event. In the create page, we have three buttons. Save as draft... the contents from the db based on the event id. But this jsp url should
How to Retrieve Excel data into mysql using type 2 JDBC-ODBC driver
How to Retrieve Excel data into mysql using type 2 JDBC-ODBC driver  .... so, can any one help me without creating DNS we should retrieve data from excel using ODBC.plz help me guys..........   Follow these steps: Open Data
retrive data from database using jsp in struts?
retrive data from database using jsp in struts?   *search.jsp* <... searchProduct(SearchDTO sdto) { String query="select * from product...()); Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521
url parameter using retrive data from database in jsp
url parameter using retrive data from database in jsp   the user can create an event. In the create page, we have three buttons. Save as draft... the contents from the db based on the event id. But this jsp url should be a public
url parameter using retrive data from database in jsp
url parameter using retrive data from database in jsp  The user can create an event. In the create page, we have three buttons. Save as draft... the contents from the db based on the event id. But this jsp url should be a public url
Connecting to the Database Using JDBC and Pure Java driver
engine we are using MySQL database server and MM.MySQL Driver... this driver to make connections to MySQL server from both Java... and for making connection we are using MM.MySQL JDBC Driver
MySQL Driver for JDBC - JDBC
MySQL Driver for JDBC  Sir, I have started reading your JDBC tutorial...... Example."); Connection conn = null; String url = "jdbc:mysql://localhost:3306   Hi,Please download the driver from http://www.mysql.com/products/connector
Unable to upload a file to mysql database using struts1
Unable to upload a file to mysql database using struts1  Hi, Below...=DriverManager.getConnection("jdbc:mysql://localhost/test","root",""); System.out.println...="multipart/form-data"> Select a File :<html:file property="file"/> <
get info from mysql using jsp and servlet
the user to key in their email address from mysql database by using servlet and jsp too...get info from mysql using jsp and servlet  HELLO! I wanna create...; String url = "jdbc:mysql://localhost:3306/"; String dbName = "register"; String
Exporting data from mysql into csv using jsp
Exporting data from mysql into csv using jsp  Hi friends.... I want to export the data from mysql to csv file using... i am having 30 columns in my database.. Eg- text1,text2,text3,....,upto text30... i want to export this data
How to retrive database information using servlet and disply in table format in browser
How to retrive database information using servlet and disply in table format in browser  Hi, any one send code how to retrive the data base information in table format in web browser
how to retrive the particular data from database in php with mysql?
how to retrive the particular data from database in php with mysql?  ..._db("samp", $con); $Name=$_POST['unames']; $data=mysql_query("SELECT * FROM tbl_sample where Name='$Name'"); /*$info=mysql_fetch_array($data);*/ while
how to insert data into database using jsp & retrive
how to insert data into database using jsp & retrive  Hello, I have created 1 html page which contain username, password & submit button. in my oracle10G database already contain table name admin which has name, password
JDBC Video tutorial - How to read Data from MySQL Database?
for reading the data from MySQL database using the JDBC driver. Check all...JDBC Beginners tutorial for reading the data from MySQL database... program, which connects to the MySQL database using pure type 4 JDBC driver
retrive image from database using jsp without stream
retrive image from database using jsp without stream  How to retrive image from database using jsp without stream like (inputStream
Retriving data from MYSQL without line break using java
Retriving data from MYSQL without line break using java  get data without line breaking from mysql table (i.e data stored as mediumtext )using java
sending data to google chart api from mysql database using java
sending data to google chart api from mysql database using java  how to send data from mysql database to google chart api using java
maven mysql jdbc driver
maven mysql jdbc driver  How to add the maven mysql jdbc driver dependency in the pom.xml file of a maven based application?   Hi, Its...;groupId>mysql</groupId> <artifactId>mysql-connector-java<
Expport data into CSV File using JDBC in Servlet
into CSV File using JDBC in Servlet   ... into CSV file using JDBC in Servlet. We have created  file "JdbcCsvFile.java" to export data from database in to CSV file. Brief
How to download MySQL JDBC driver?
program. To connect to MySQL database from Java program we need JDBC Driver of MySQL... to download and use MySQL JDBC Driver: MySQL JDBC driver can be downloaded from https...How to download MySQL JDBC driver?  Hi, What is JDBC Driver? How
retrive data from database?
retrive data from database?  hellow i have a database sheet name..... now i want retrive sn,roll no and name and textbox like....,rllno,and name retrive
place data in text fields from database using jdbc
place data in text fields from database using jdbc  i want get the data from database and place the records in the respective textfields using jdbc and swing like eno,ename,loc from emp table
Displaying Mysql clob data using Servlet
Displaying Mysql clob data using Servlet .In this Section, we will display a clob data from a table of database using servlet. A CLOB is a Character Large... any portion of the CLOB data. 2.Equallity of 2 CLOBs can  be check by using
Upload Exce Data into MySql Using Jsp and Servlet - JSP-Servlet
Upload Exce Data into MySql Using Jsp and Servlet  now i am doing a project my concept is to insert the Excel File Data is uploaded and inserted into Mysql Database table so please give the coding to me, it's very urgent for me
retrive data from database
retrive data from database   hi.. i made a application form. it's have attribute s.no,name,roll no and i enter a few records. now i want to view all record not in database access sheet i want to view it at any another
retrieve related data from database using jsp and mysql
retrieve related data from database using jsp and mysql  Hi sir, please give some example of jsp code for retrieving mysql database values in multiple dropdown list. if we change a value in a dropdown its related value must
Data needs to be gathered in XML file from the database (MySql) using JSP
Data needs to be gathered in XML file from the database (MySql) using JSP ... data regarding particular id from the database table. Data needs to be gathered in XML file from the database (MySql) using appropriate JSP/Java Bean functions
how to display data from mysql table in text box using jsp??
how to display data from mysql table in text box using jsp??  <p>hi, i have a written a code to display data from a mysql table into txtboxes...;body> &lt;% try {</p> <p>String connectionURL = "jdbc
Tutorials   
Java Spring Hibernate Struts Training java.lang.classnotfoundexception com.mysql.jdbc.driver how to retrieve text and images from mysql database and show on html page using jsp servlet How to install Neo4j on Ubuntu 15.10? please help me in these prog MYSQL - mysql copy table to another table example by creating new table solution for mapping hibernate and pojos from net beans through database Connect GWT application with Oracle inventory System of Medical Store inventory System of Medical Store inventory System of Medical Store inventory System of Medical Store This code have created jTable that connected with a database.every cell of last column have a button.But this button doesn't work properly.Where is the error java program Java Database Program jdbc Database connection class in a live project ..?? What is JDBC architecture? Unable to Create DSN for excel to ms access importing data and edit that data Database Scrolling Buttons how to use foreign key in java How to delete content of a log file from linux terminal? JSP-Oracle connectivity Student Management System Java code for Saving Marathi (Indian local language ) in Mysql and retrieving the same crud operations with foreign key constraint. I really need help with this assignment question Please help me out Please Backup Failed Mysqldump Got Errno 28 On Write Upgrade MySQL 5.1 to 5.5 in cpanel mysqldump all databases com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'jpa.sequence' doesn't exist persistence xml class element persistence.xml for MySQL MySQL JDBC Driver pom dependency code Blob column jdk6 and oracle 8i connexion oracle 8i et jdk6 java [ cannot retrive date from sql ] why?? Order Entry System How to threow timeout exception when DB is not responding How to threow timeout exception when DB is not responding This is the employee form to add data to mysql database but I got error of NullPointerException, Is this write code please give me feedback as soon as possible make a method which takes user name & pwd as parameter & validate them against the database. If the corresponding user exist return true otherwise false. prabhakar validating credentials and displaying error message in login .jsp if not valid JDBC jdbc jdbc code register servlet vibhu

Ads

 
Advertisement null

Ads