We would like to know whether we have to use another connector (driver)
We also tried putting the driver in tomcat\webinf\lib and putting it in
classpath as well but in vain.
Kindly let us know the solution .Its urgent.
This is our class which provides connection to db.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Connect
{
public static Connection conn;
/**
* This method will return a connection to the database.
* @return Connection: A connection object to the database.
*/
Connection getConnection() throws Exception
{
if (conn == null)
{
String driverName = new String();
if ((null == driverName) || "".equals(driverName))
{
driverName = "com.mysql.jdbc.Driver";
}
String connString = new String();
if ((null == connString) || "".equals(connString))
{
connString = "jdbc:mysql://localhost:3306/project";
//project is database name . 3306 is port number
}
String userName = new String();
if ((null == userName) || "".equals(userName))
{
userName = "vartej";
}
String password = new String();
if ((null == password) || "".equals(password))
{
password = "vartej";
}
// Driver driver = null;
try
{
Connection conn =
DriverManager.getConnection("jdbc:mysql://localhost/project?
user=vartej&password=vartej");
// Do something with the Connection
// ....
}
catch (SQLException ex)
{
// handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
/*
try
{
//Driver driver =
(Driver)Class.forName(driverName).newInstance();
driver = (Driver)Class.forName(driverName).newInstance();
}
catch(Exception e)
{
System.out.println("Driver Error");
System.out.println(e.getMessage());
}
DriverManager.registerDriver(driver);
conn = DriverManager.getConnection(connString, userName
,password);*/
}
return conn;
}
}