facing issue when using JDBC in TomCat 7 with Struts

Posted by Chethu2288 on Stack Overflow See other posts from Stack Overflow or by Chethu2288
Published on 2012-03-31T17:24:21Z Indexed on 2012/03/31 17:29 UTC
Read the original article Hit count: 188

Filed under:
|
|
|

Am developing a web application using Struts 2 where am trying to insert some values into my local MySql database. The code for connecting and accessing database works fine in console application. but its giving "java.lang.ClassNotFoundException: com.mysql.jdbc.Driver" exception when i tried the same code in Struts. Kindly help me on this.

Connection conn = null;
          String url = "jdbc:mysql://localhost:3306/";
          String dbName = "testdatabase";
          String driver = "com.mysql.jdbc.Driver";
          try
            {
                Class.forName(driver).newInstance();
                  conn = DriverManager.getConnection(url+dbName,"root","root");

                Statement statement=conn.createStatement();
                System.out.println("HelloWorld.execute()");
                int i= statement.executeUpdate("INSERT INTO testTable VALUES('15','Lucky')");
                System.out.println("res: "+i);

            }
        catch(Exception e)
        {
            System.out.println(e);
            //setMessage(e.getMessage());
        }

Awaiting your response.

© Stack Overflow or respective owner

Related posts about mysql

Related posts about jdbc