title: Struts2 example, not inserting records in mysql database because connection object is getting null
body: <p>This Code is working fine with simple application so the drivers are fine.
  so why the connection object is not able to initialise with drivers. </p>
  
  <p>import java.sql.Connection;</p>
  
  <p>import java.sql.DriverManager;</p>
  
  <p>import java.sql.SQLException;</p>
  
  <p>import java.sql.Statement;</p>
  
  <p>import com.opensymphony.xwork2.ActionSupport;</p>
  
  <p>public class Insert extends ActionSupport {</p>
  
  <pre><code>public String execute() throws Exception, SQLException {
  
      String sql = "";
  
      String url = "jdbc:mysql://localhost:3306/test";
  
      //String dbName = "test";
  
      String driverName = "org.gjt.mm.mysql.Driver";
  
      String userName = "root";
  
      String password = "root";
  
      Connection con=null;
  
      Statement stmt=null;
  
      try {
  
          Class.forName(driverName).newInstance();
  
          con = DriverManager.getConnection(url, userName, password);
  
          stmt = con.createStatement();
  
      } catch (Exception e) {
  
          System.out.println(e.getMessage());
  
      }
  </code></pre>
  
  <p>}</p>