Results 1 to 10 of 10
  1. #1
    justbeller is offline Member
    Join Date
    Dec 2010
    Posts
    57
    Rep Power
    0

    Post Direct Access Connectivity with password

    Hello Guys

    I'm direct access connectivity its working but when i'm gonna set password on access database i'm getting nullpointerexception

    here is the code:

    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

    String filename = "database/data.mdb";
    String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
    database += filename.trim()+";DriverID=22;READONLY=true";
    con = DriverManager.getConnection(database, "", "java");

    please help

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,002
    Rep Power
    20

    Default Re: Direct Access Connectivity with password

    Where are you getting the null pointer exception?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    justbeller is offline Member
    Join Date
    Dec 2010
    Posts
    57
    Rep Power
    0

    Default Re: Direct Access Connectivity with password

    I'm getting exception here

    Connection con = DriverManager.getConnection(database, "", "java");

    what's the problem can you help me

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,002
    Rep Power
    20

    Default Re: Direct Access Connectivity with password

    You'll need to give us the stack trace, as there's nothing on that line that would be null.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    justbeller is offline Member
    Join Date
    Dec 2010
    Posts
    57
    Rep Power
    0

    Default Re: Direct Access Connectivity with password

    Here is exception

    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at DatabaseManager.getPassword(DatabaseManager.java:4 84)
    at JPasswordPanel.showPanel(JPasswordPanel.java:31)
    at Main$1.run(Main.java:43)
    at java.awt.event.InvocationEvent.dispatch(Invocation Event.java:251)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.j ava:705)
    at java.awt.EventQueue.access$000(EventQueue.java:101 )
    at java.awt.EventQueue$3.run(EventQueue.java:666)
    at java.awt.EventQueue$3.run(EventQueue.java:664)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 675)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:211)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:128)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:117)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:113)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:105)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:90)

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,002
    Rep Power
    20

    Default Re: Direct Access Connectivity with password

    And the code for getPassword, highlighting line 484.

    Because if it's that line then either you have an object called DriverManager which is null (rather than using the static getCOnnection() method on the class), or you are not running the code you think you are.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    justbeller is offline Member
    Join Date
    Dec 2010
    Posts
    57
    Rep Power
    0

    Default Re: Direct Access Connectivity with password

    I'm using static block for connectivity

    DatabaseManager{
    static Conncetion con;
    static{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

    String filename = "database/data.mdb";
    String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
    database += filename.trim()+";DriverID=22;READONLY=true";
    con = DriverManager.getConnection(database, "", "java");
    }

    public static String getPassword() throws SQLException{
    Statement st = con.createStatement();
    ResultSet rs = st.executeQuery("SELECt * from password");
    if(rs.next()){
    return rs.getString("pass");
    }
    return "";
    }
    }

    And in DriverManager.getConnection(database, "", "java"); initializing the null value in Connection bbject
    if I removing the pass word from ms access db the prgram is running but witgh its not working...
    now understand

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,002
    Rep Power
    20

    Default Re: Direct Access Connectivity with password

    When posting code please use [code] tags [/code].

    So, con is null.
    Which implies that the static initialiser is throwing an exception.
    Now, since you would not be able to compile the above without a try/catch block to handle the SQLException that getConnection() throws, I am guessing the above is not your actual code and that your actual code catches the SQLException and does nothing with it. Or you are ignoring it in your logs.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  9. #9
    justbeller is offline Member
    Join Date
    Dec 2010
    Posts
    57
    Rep Power
    0

    Default Re: Direct Access Connectivity with password

    sorry for [code] tags

    sorry, i didn't write try-catch block in post.

    now Its giving me this exception

    java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Not a valid password.

    im writing correct password

  10. #10
    justbeller is offline Member
    Join Date
    Dec 2010
    Posts
    57
    Rep Power
    0

    Default Re: Direct Access Connectivity with password

    I got the solution

    I'm setted database password thats my mistake
    now i'm set user passwords, now its working

    thanks "Tolls" for discussion

Similar Threads

  1. Replies: 0
    Last Post: 07-31-2012, 08:33 AM
  2. Replies: 0
    Last Post: 09-14-2011, 09:44 AM
  3. Replies: 5
    Last Post: 10-29-2009, 07:56 AM
  4. DSN less connectivity to Ms ACCESS
    By sayan751 in forum Advanced Java
    Replies: 2
    Last Post: 03-28-2009, 04:27 PM

Posting Permissions

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