-3
public static Connection ConnectDB() {
    try {
        Class.forName("com.mysql.jdbc.Driver");
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/hms_db","root","golu");
        return con;
    } catch(ClassNotFoundException | SQLException e) {
        JOptionPane.showMessageDialog(null, e);
        return null;
    }      
}
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException  
  at Login.txtPasswordKeyPressed(Login.java:204)  
  at Login.access$300(Login.java:14)  
  at Login$4.keyPressed(Login.java:74)  
  at java.awt.Component.processKeyEvent(Component.java:6493)  
  at javax.swing.JComponent.processKeyEvent(JComponent.java:2832)  
  at java.awt.Component.processEvent(Component.java:6312)  
  at java.awt.Container.processEvent(Container.java:2236)  
  at java.awt.Component.dispatchEventImpl(Component.java:4891)  
  at java.awt.Container.dispatchEventImpl(Container.java:2294)  
  at java.awt.Component.dispatchEvent(Component.java:4713)  
  at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1954)
  at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:806)
  at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:1074)
  at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:945)
  at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:771)
  at java.awt.Component.dispatchEventImpl(Component.java:4762)  
  at java.awt.Container.dispatchEventImpl(Container.java:2294)  
  at java.awt.Window.dispatchEventImpl(Window.java:2750)  
  at java.awt.Component.dispatchEvent(Component.java:4713)  
  at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)  
  at java.awt.EventQueue.access$500(EventQueue.java:97)  
  at java.awt.EventQueue$3.run(EventQueue.java:709)  
  at java.awt.EventQueue$3.run(EventQueue.java:703)  
  at java.security.AccessController.doPrivileged(Native Method)  
  at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
  at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
  at java.awt.EventQueue$4.run(EventQueue.java:731)  
  at java.awt.EventQueue$4.run(EventQueue.java:729)  
  at java.security.AccessController.doPrivileged(Native Method)  
  at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
  at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)  
  at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
  at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
  at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
  at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) 
  at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)  
  at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

My username is "admin" and password is "12345". Please someone help me to resolve these error.

Tom
  • 16,842
  • 17
  • 45
  • 54
  • 2
    A couple of comments: Don't give out your credentials to the whole world by posting them on Stack Overflow. Also, does your `1` key still function properly after holding it down for so long? – Tim Biegeleisen Nov 09 '15 at 12:53
  • 1
    Possible duplicate of [What is a Null Pointer Exception, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it) – Andy Turner Nov 09 '15 at 12:55
  • 1
    When you post an exception stacktrace, then place post the correct one. This one is not related to your question. – Tom Nov 09 '15 at 13:23
  • What is here: Login.java, line 204? – Dave Richardson Nov 09 '15 at 13:51

3 Answers3

0

You passing 'root' like username and 'golu' like passwork it´s correct? Because in your post you say that the username and password are other.

Chema
  • 67
  • 4
  • 17
0

You are passing wrong username and password for your mysql database to get a jdbc connection.

 Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/hms_db","<valid-mysql-username>","<valid-mysql-password>");
Imrank
  • 1,009
  • 5
  • 15
0

Make sure you have included the library of JDBC driver on your project.

And change it:

Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/<database name>","<user>","<password>");
Tom
  • 16,842
  • 17
  • 45
  • 54