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
Re: Direct Access Connectivity with password
Where are you getting the null pointer exception?
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
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.
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)
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.
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
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.
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
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