You should use the followin format for your connections string.
private String host="127.0.0.1";
private String user="mysqlusername";
private String pass="mysqlpassword";
private String db="yourdatabasename";
private String dburl = null;
private Connection con;
private String error;
public void connect() throws ClassNotFoundException, SQLException,
Exception
{
try
{
Class.forName("org.gjt.mm.mysql.Driver");
// create connection string
dburl = "jdbc:mysql://" + host + "/" + db +
"?user=" + user + "&password=" + pass;
con = DriverManager.getConnection(dburl);
}
catch (ClassNotFoundException cnfe)
{
error = "ClassNotFoundException: Could not locate DB
driver.";
throw new ClassNotFoundException(error);
}
catch (SQLException cnfe)
{
error = "SQLException: Could not connect to
database.";
throw new SQLException(error);
}
catch (Exception e)
{
error = "Exception: An unknown error occured while
connecting " +
"to the database.";
throw new Exception(error);
}
} // end of connect method
Jason Lanpher
[EMAIL PROTECTED]
http://www.stealthnetworking.com
Remember there are only 10 types of people in this world. Those who
understand Binary and those who don't.
-----Original Message-----
From: Luong Phan [mailto:[EMAIL PROTECTED]
Sent: Friday, August 22, 2003 3:31 AM
To: [EMAIL PROTECTED]
Subject: Suitable Driver Error
Hi all,
In my web application, I use mysql supported by Redhat Linux 7.3 to store
database, jakarta-tomcat-3.2.4, mysql-connector-java-3.0.6-stable-bin.jar,
and JSP.
Every time, I run the program:
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Data {
private Connection connection;
private Statement statement;
public Data() throws ClassNotFoundException,SQLException{
String DBDriver=null;
String url=null;
String username=null;
String password=null;
password="myPassword";
username="myUserName";
url="dbc:mysql://localhost/gmds";
DBDriver="com.mysql.jdbc.Driver";
try{
Class.forName(DBDriver);
connection=DriverManager.getConnection(url,username,password);
statement=connection.createStatement();
}catch(ClassNotFoundException e){
System.err.println("Failed to load JDBC/ODBC driver.");
e.printStackTrace();
}catch(SQLException e){
System.err.println("Unable to connect");
e.printStackTrace();
}
}
...
I get the error:
Unable to connect
java.sql.SQLException: No suitable driver at
java.sql.DriverManager.getConnection(DriverManager.java 532)
...
What is suitable driver for my application? Please give me some words of
advice!
Thanks a lot.
LuongPhan
---------------------------------
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]