Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 168713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:30:07+00:00 2026-05-11T12:30:07+00:00

This Code is working fine with simple application so the drivers are fine. so

  • 0

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.

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.SQLException;

import java.sql.Statement;

import com.opensymphony.xwork2.ActionSupport;

public class Insert extends ActionSupport {

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());      } 

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T12:30:07+00:00Added an answer on May 11, 2026 at 12:30 pm

    What does the exception say? A NullPointerException on createStatement?

    In any case, has the class been loaded; is the class on the classpath (i.e. the MySQL jar on the classpath?)

    Check the object returned from Class.forName() to check whether the class has been found.

    After your comment it is clear that you have a classpath problem. The mysql jar is not on the classpath. I assume you are talking about a web app deliverable (war file), as changing the build path in eclipse is trivial.

    In a web application deployed in, for example, tomcat you can look into <webapp-name>/WEB-INF/lib. The file WEB-INF/lib/mysql-connector-java-5.0.5.jar, or something similar, should be there.

    If you have a war file (not yet deployed) you can extract it using the command line tool ‘jar’, or get a file listing from it. If you do (on a command line) jar tf | grep mysql the jarfile should be visible. If you use windows; WinRAR (and probably WinZip) can also open warfiles. In WEB-INF/lib a MySQL jar should be visible.

    If you use maven to build your web app; don’t forget to add a dependency to the mysql jar. If you use ant to build; don’t forget to copy the mysql jar file into WEB-INF/lib before creating the war file.

    Please note that currently the recommended driver to ask for is ‘com.mysql.driver.Driver’, and not ‘org.gjt.mm.mysql.Driver’. You can try to load that Driver class in stead of the older driver; further; check whether this driver is actually in the mysql jar (jar tf mysq.jar | grep Driver or so). If the Driver is in the mysql jar and the mysql jar is on the classpath of the webapp (in WEB-INF/lib) and there is only one mysql jar there (version conflicts are no fun), and it still does not work I really don’t know what could be wrong. I think I’d download the driver jar again from MySQL and try again.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 131k
  • Answers 131k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can use the System.Diagnostics.EventLog.WriteEntry function to write entries to… May 12, 2026 at 6:18 am
  • Editorial Team
    Editorial Team added an answer Your problem is that you can't descend that many levels… May 12, 2026 at 6:18 am
  • Editorial Team
    Editorial Team added an answer It depends on whether your list elements are mutable, if… May 12, 2026 at 6:18 am

Related Questions

I've got a c# application that plays simple wav files through directsound. With the
I'm creating a custom script control in ASP.NET The purpose of the control is
EDIT: See my working code in the answers below. In brief: I have a
I need some mind reading here, since I am trying to do what I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.