| Mailing List | | Home | | MySQL General - General MySQL discussion | | MaxDB - Everything about MaxDB, formerly known as SAP DB | | MySQL on Win32 - Runing MySQL on Windows 9x/Me/NT/2000/XP | | Java Help - Mostly related to the MySQL Connector/J driver | | ODBC - ODBC with the MySQL Connector/ODBC driver | | Perl - Perl support for MySQL with DBI and DBD::mysql | | MySQL++ - Programming with the C++ API to MySQL |
|
|
  | |  | Not Getting DB Connection | Not Getting DB Connection 2004-06-06 - By Scott D. Spiegler
Back Hi,
I am using the following code but not getting a
connection. :( Can someone tell me what I am doing
incorrectly?
Thanks, Scott
package database_test;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.DriverManager;
import java.sql.SQLException;
// Notice, do not import com.mysql.jdbc.*
// or you will have problems!
/**
* <p >Title: Phone # regex:
^([(]?\d{3}[-)]\d{3}-\d{4})*$ </p >
* <p >Description: </p >
* <p >Copyright: Copyright (c) 2004 </p >
* <p >Company: </p >
* @(protected) unascribed
* @(protected) 1.0
*/
public class DBConnector
{
//Class State
private String dbuser,dbpasswd,dburl;
public DBConnector()
{
dbuser= "sspiegler ";
dbpasswd= "cuatro ";
dburl=
"jdbc:mysql://localhost:3306/menagerie?user= "+dbuser+ "&password= "+dbpasswd;
}
public DBConnector(String aDburl,String
aDbuser,String aDbpasswd)
{
this.dbuser=aDbuser;
this.dbpasswd=aDbpasswd;
this.dburl=aDburl;
}
public Connection getConnection () throws
SQLException
{
ResultSet rs=null;
Connection conn=null;
try
{
conn = DriverManager.getConnection(dburl);
Statement state = conn.createStatement();
rs = state.executeQuery( "SELECT * FROM
pets ");
if (rs != null)
{
// here you would do something with
the ResultSet
}
}
finally
{
if (rs != null)
{
rs.close();
}
}
return conn;
}
/**
* *** for testing purposes only ***
*/
public static void main(String[] args)
{
Connection conn = null;
DBConnector dbc = new DBConnector();
try
{
conn = dbc.getConnection();
}
catch(SQLException sqle)
{
System.out.println( "SQLException: " +
sqle.getMessage());
System.out.println( "SQLState: " +
sqle.getSQLState());
System.out.println( "VendorError: " +
sqle.getErrorCode());
}
}
}
=====
We don 't see things as they are, we see things as we are.
--Anais Nin
__ ____ ____ ____ ____ ____ ______
Do you Yahoo!?
Friends. Fun. Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/
--
MySQL General Mailing List
For list archives:
http://lists.mysql.com/mysql
To unsubscribe:
http://lists.mysql.com/mysql?unsub=mysql
@(protected)
|
|
 |