Results 1 to 3 of 3
  1. #1
    pateldpk is offline Member
    Join Date
    Apr 2012
    Posts
    27
    Rep Power
    0

    Default Java with MS Access Database User login

    Friends need help...

    I'm trying to Connect with MS Access database.. and the connection succesfully established .. but when i'm trying to check whether username and password is matching or not with databse login table ..its not working..
    might be there is a Problem with try block inside check method... check image also..
    Database Name=loginuser1
    Table Name=login

    I have also configured the ODBC data source ....

    Below is the code...


    import java.sql.*;
    public class check{
    Connection con;
    Statement st;
    ResultSet rs;

    public check(){
    connect();
    }
    public void connect(){

    try{
    String driver="sun.jdbc.odbc.JdbcOdbcDriver";
    Class.forName(driver);
    String db="jdbc:odbc:loginuser1";
    con=DriverManager.getConnection(db);
    st=con.createStatement();
    System.out.println("Connection established");
    }
    catch(Exception ex){
    System.out.println("Connection problem"+ex);
    }
    }
    public static void main(String[] args){
    String userName="Deepak";
    int password=123;
    check ck=new check();
    ck.check(userName,password);
    }
    public void check(String userName,int password){
    try{
    String sql="select user,pass from login where user='"+userName+"'pass='"+password+"'";
    rs=st.executeQuery(sql);
    System.out.println(rs);
    int count=0;
    while(rs.next()){
    count=count+1;
    }
    if(count==1){
    System.out.println("SQL done");
    }else{
    System.out.println("again error");
    }
    }catch(Exception ex){System.out.println("Problem with query...");}-------->(showing this user-defined error)
    }
    }

    problem with try block...


    Java with MS Access Database User login-databse.jpg

  2. #2
    pateldpk is offline Member
    Join Date
    Apr 2012
    Posts
    27
    Rep Power
    0

    Default Re: Java with MS Access Database User login

    When i execute .class file ....

    Java with MS Access Database User login-databse2.jpg

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,830
    Rep Power
    19

    Default Re: Java with MS Access Database User login

    1. Please use [code] tags [/code] when posting code so it retains formatting and is readable.
    2. When catching exceptions it's advisable to do <exception>.printStackTrace() to get as much information about the exception as possible.
    3. Finally, I'd recommend using a PreparedStatement and binding (eg setString()) the variables in. Concatenating your parameters into your SQL like that invariably leads to bugs.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. how to login to website to get access using java?
    By theChameleon in forum Advanced Java
    Replies: 0
    Last Post: 10-29-2010, 06:20 PM
  2. Replies: 1
    Last Post: 03-15-2010, 01:39 AM
  3. Single login for a user at a time
    By mitali l joshi in forum Java Servlet
    Replies: 4
    Last Post: 01-22-2010, 10:23 AM
  4. Replies: 0
    Last Post: 06-25-2008, 12:41 PM
  5. Login user name - for all platforms.
    By Eranga in forum Advanced Java
    Replies: 0
    Last Post: 03-17-2008, 05:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •