Here's The Deal :)
To Pass a username and Password via JDBC, you should pass it in the
'url' string... 
Try this :
DriverManager.getConnection("jdbc:mysql://localhost:3306/test?user=[user
]&password=[pass]");

I Find it's about the most reliable Way to go :)

<pre>
_/_/_/_/  _/_/_/_/ +---Research Programmer---+
_/_/ONE _/_/       |     Mark C. Roduner     |
_/_/_/TRUE_/_/_/   |     [EMAIL PROTECTED]      |
_/_/    ENIGMA_/_/ |      [EMAIL PROTECTED]     |
_/_/_/_/_/_/_/_/   +-Medical Sytematics Inc.-+
 ENIGMATIC SOURCE
</Pre>

-----Original Message-----
From: Todd O'Bryan [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, April 02, 2003 10:52 AM
To: Mark Matthews
Cc: [EMAIL PROTECTED]
Subject: Re: JDBC can't connect, but command line can...


>
> When you don't specify a hostname (and 'localhost' doesn't count, use
> '127.0.0.1') to the mysql commandline client, it uses Unix domain
> sockets to connect to the server.
>
> JDBC has to use TCP/IP, because Java doesn't have support for Unix
> domain sockets.
>
> What happens if you do:
>
> mysql -h 127.0.0.1 -u tobryan1 -p
>
It works.

[iBook:1]> mysql -h 127.0.0.1 -u tobryan1 -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 13 to server version: 4.0.12-standard

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

> What happens if you telnet to 'localhost 3306'...does the server 
> answer, or do you just sit forever?
Actually, something happens that I don't understand:

[iBook:3]> telnet localhost 3306
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
0
4.0.12-standardTwz!2tvp,

Bad handshakeConnection closed by foreign host.
---------------------------
4.0.12 looks like it's MySQL, but I have no idea what this means.

This at least looks like it should tell somebody something. Any idea 
where to go next?

Thanks!

Todd

On Wednesday, April 2, 2003, at 10:56  AM, Mark Matthews wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Todd O'Bryan wrote:
> | I've managed to get mysql up and running again (I don't know how)
but
> | JDBC won't connect to it.
> |
> | Here's my little simple code:
> | ------------------------------------------------
> | import java.sql.*;
> | import java.io.*;
> |
> | public class MySQLTester {
> |
> |     public static void main(String[] args) throws Exception {
> |         Class.forName("com.mysql.jdbc.Driver");
> |         System.out.println("Loaded Driver...");
> |
> |         DriverManager.setLogWriter(new PrintWriter(System.out));
> |
> |
> |         Connection con =
> |
DriverManager.getConnection("jdbc:mysql://localhost/test","tobryan1",
> | "aoeuidhtns");
> |         System.out.println("Got connection...");
> |
> |         Statement s = con.createStatement();
> |         s.executeUpdate("CREATE TABLE students (login char(8), last
> | VARCHAR(20), first VARCHAR(20), " +
> |                         "nickname VARCHAR(20), course CHAR(4),
period
> | INT)");
> |     }
> | }
> | ------------------------
> | And here's what happens:
> |
> | [iBook:18]> java MySQLTester
> | Loaded Driver...
> | DriverManager.getConnection("jdbc:mysql://localhost/test")
> |     trying
> | driver[className=com.mysql.jdbc.Driver,[EMAIL PROTECTED]
> |
> | and it hangs forever.
> |
> | -------------------------
> | I can connect to mysql using the same user name and password, 
> however....
> |
> | [iBook:20]> mysql -u tobryan1 -p
> | Enter password:
> | Welcome to the MySQL monitor.  Commands end with ; or \g.
> | Your MySQL connection id is 9 to server version: 4.0.12-standard
> |
> | Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
> |
> | mysql> use test;
> | Database changed
> | mysql> show tables;
> | Empty set (0.00 sec)
> |
> | mysql>
> | -------------------------
> | I've searched for info on troubleshooting the JDBC connection and
> | skimmed the O'Reilly book by George Reese, but to no avail.
> |
> | Should I just give up, or is there something I can do to figure out
> | what's going wrong?
> |
> | Thanks,
> | Todd
>
>       -Mark


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to