If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > MYSQL and Tomcat Connection

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-08-04, 03:11
tej tej is offline
Registered User
 
Join Date: Apr 2004
Posts: 2
MYSQL and Tomcat Connection

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;

}
}
Attached Files
File Type: zip pro.zip (40.1 KB, 24 views)
Reply With Quote
  #2 (permalink)  
Old 04-08-04, 03:34
ika ika is offline
Registered User
 
Join Date: Oct 2003
Location: Slovakia
Posts: 482
Re: MYSQL and Tomcat Connection

Quote:
Originally posted by tej
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;

}
}
This is Java related question, please go to JAVA section
Reply With Quote
  #3 (permalink)  
Old 04-08-04, 16:08
localt localt is offline
Registered User
 
Join Date: Mar 2004
Posts: 16
Re: MYSQL and Tomcat Connection

try loading the class before defining the connection.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On