title: Class.forName doesn't work while trying to connect to MySQL database
body: <p>I have a problem using mysql. It seems that when the program runs into this part, it doesn't continue [SOLVED]</p>
  
  <pre><code>        try{
          //Load the Driver Class
          Class.forName("com.mysql.jdbc.Driver");
  </code></pre>
  
  <p>I think there is a problem in this part of code. because I tried this, the JOptionPane popped up:</p>
  
  <pre><code>        try{
          JOptionPane.showMessageDialog(null, "Ok!");
          //Load the Driver Class
          Class.forName("com.mysql.jdbc.Driver");
  </code></pre>
  
  <p>but, when I wrote the code like this, nothing happens:</p>
  
  <pre><code>        try{
          //Load the Driver Class
          Class.forName("com.mysql.jdbc.Driver");
          JOptionPane.showMessageDialog(null, "Ok!");
  </code></pre>
  
  <p>Any suggestions? Thanks.</p>
  
  <p>BTW, this is my whole program</p>
  
  <pre><code>private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
      // TODO add your handling code here:
      String user = userName.getText();
      final String URL = "jdbc:mysql://localhost:3306/videorental";
  
      if(user.equals("")){
          JOptionPane.showMessageDialog(null, "Fields should not be empty", "Error", JOptionPane.ERROR_MESSAGE);
      }
      else{
          try{
          //Load the Driver Class
          Class.forName("com.mysql.jdbc.Driver");
          //Create the connection using the static getConnection method
          JOptionPane.showMessageDialog(null, "Connecting to database");
          Connection con = DriverManager.getConnection(URL, "root", "");
          //Create statement to execute the SQL statement
          JOptionPane.showMessageDialog(null, "Creating a statement");
          Statement stmt = con.createStatement();
          //Check the username
          ResultSet rs = stmt.executeQuery("select * from 'user_tbl' where user_id = '"+user+"' ");
          if(rs.next()){
              String uname = rs.getString("user_id");
              if(user.equals(uname)){
                  JOptionPane.showMessageDialog(null, "Thank you!");
              }
              else{
                  JOptionPane.showMessageDialog (null, "You are not registered.");
              }
          }
          }
          catch (Exception e) {
              e.printStackTrace();
          }
      }     
  
  
  }                                  
  </code></pre>
  
  <p>So I tried putting e.printStackTrace(), sorry I'm really a newbie in using mySQL. So here is the result... [SOLVED]</p>
  
  <pre><code>java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
      at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Class.java:190)
      at user.loginFrame.jButton1ActionPerformed(loginFrame.java:113)
      at user.loginFrame.access$000(loginFrame.java:14)
      at user.loginFrame$1.actionPerformed(loginFrame.java:48)
      at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
      at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
      at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
      at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
      at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
      at java.awt.Component.processMouseEvent(Component.java:6505)
      at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
      at java.awt.Component.processEvent(Component.java:6270)
      at java.awt.Container.processEvent(Container.java:2229)
      at java.awt.Component.dispatchEventImpl(Component.java:4861)
      at java.awt.Container.dispatchEventImpl(Container.java:2287)
      at java.awt.Component.dispatchEvent(Component.java:4687)
      at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
      at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
      at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
      at java.awt.Container.dispatchEventImpl(Container.java:2273)
      at java.awt.Window.dispatchEventImpl(Window.java:2719)
      at java.awt.Component.dispatchEvent(Component.java:4687)
      at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
      at java.awt.EventQueue.access$200(EventQueue.java:103)
      at java.awt.EventQueue$3.run(EventQueue.java:694)
      at java.awt.EventQueue$3.run(EventQueue.java:692)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
      at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
      at java.awt.EventQueue$4.run(EventQueue.java:708)
      at java.awt.EventQueue$4.run(EventQueue.java:706)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
      at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
      at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
      at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
      at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)    
  </code></pre>
  
  <p>And I don't have any idea what these errors are. Can anyone help me? Thanks.</p>
  
  <p>BTW, I'm using netbeans as an IDE.</p>
  
  <p>Thanks guys for the help but a new problem arises, it says that I have MYSQLSYntaxError </p>
  
  <pre><code>com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your   SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''user_tbl' where user_id = '12345678'' at line 1
  </code></pre>