jsp login using a access database

Posted on 2008-02-02
Medium Priority
Last Modified: 2012-08-13
I am using NetBeans IDE 5.5.1 and I have a Login.jsp and a access database. How do i create a login from my jsp page that reads from my database?
                <input type="text" name="ID" id="ID" />
                <p>ID &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <input type="password" name="Occupation" id="Occupation" />
  <input name="Login" type="button" id="Login" value="Login" />

Open in new window

Question by:tdawg6

Accepted Solution

mohammedf earned 2000 total points
ID: 20804784
here is a full working application
LVL 27

Expert Comment

ID: 20808031
Netbeans has good online documentation.  This page:
walks you through the steps to create a form-based login for Tomcat (or Sun's Web app server).

You don't have to use the mechanism that comes with Tomcat, however.  You could  create a form and have users log in.  Then you could write your own code to keep the pages secure from non-logged in Web site visitors.  It's easier to use a login package, like the one that comes with Tomcat, but you don't have to.

If you are asking how to make a query to an Access db from a JSP, here is a simple example:

Connection con = null;
Statement stmt = null;
ResultSet rs = null;

      Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
      con = DriverManager.getConnection( "jdbc:odbc:MyDbName", dbUser, dbPassword );
      stmt = con.createStatement( );

      rs = stmt.executeQuery("Select Id, Field1 from Table 1");
      while( rs.next() ) {
            int recId = rs.getInt("Id");
            String field1 = rs.getString("Field1");
catch( SQLException e ) {

This uses the JDBC-ODBC driver to access your Access db.  You have to have an ODBC connection defined for your Access db (as a System DSN), which in this example is named MyDbName.  Access dbs often don't have usernames and passwords.  If you don't, you can leave off the dbUser and dbPassword parameters to the getConnection call.

Expert Comment

ID: 20840159
rose india does a nice app for you, if you replace the code in the checkValidUser to do a sql select on your DB it will work a treat:


ResultSet rs = stmt.executeQuery("select name * from userTable where userId ='1'");

if(rs = null)
           user does not exist
      user exists

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question