David and Paul:
It turns out that my port is 3306, the default. Apparently the error in my
test servlet occurred for an entirely different reason.
When my URL was set up properly (jdbc:mysql://localhost:3306/my_database), I
was closing a ResultSet even though I had not instantiated it in the first
place. The result: NullPointerException.
Your help was confirmation that the problem was not port related, and got me
thinking about the problem from a different angle.
Thanks,
Martin Hollyer
----- Original Message -----
From: David Wall <dwall@stripped>
To: Martin Hollyer <zorron@stripped>; <java@stripped>
Sent: Tuesday, June 01, 1999 12:15 AM
Subject: Re: What are Unix Sockets and What Port does the database use?
> You want to just use JDBC-style URLs -- things could vary depending on
your
> JDBC driver), such as:jdbc:mysql://myhostname.com:3306/my_database
>
> On the local machine you just use jdbc:mysql://localhost:3306/my_database
>
> I doubt that any of the JDBC drivers make use of UNIX style sockets, even
if
> your JVM is running on the same Unix box. But, if you wrote your own
access
> to MySql, the Unix domain sockets are faster. I wouldn't fret over that,
> though.
>
> David
Thanks David,
Unfortunately, my Internet Provider has a
>
>
> ----- Original Message -----
> From: Martin Hollyer <zorron@stripped>
> To: <java@stripped>
> Sent: Monday, May 31, 1999 9:40 PM
> Subject: What are Unix Sockets and What Port does the database use?
>
>
> What are Unix Sockets and What Port does the database use?
> =========================================================
>
> Martin Hollyer, MySQL newbie here. I have done a number of
> servlet JDBC applications with JDBC and Access.
>
> Recently, I installed MySQL on my local Window NT computer
> and have had no difficulty connecting to MySQL on my local machine.
>
> In order to create Java Database applications, I have to know the
> port number my database uses. With MySQL on my Local WinNT
> machine, I type the status command:
>
> status
>
> mysql Ver 9.13 Distrib 3.21.13a-gamma, for Win/95 i586
>
> Connection id: 7
> Current database: hollyer
> Current user: tr003073@localhost
> Server version 3.21.29a-gamma-debug
> Protocol version 10
> Connection Localhost via TCP/ip
> TCP Port 3306
> Uptime: 2 hours 1 minute 1 second
>
> Threads: 3 Questions: 673 Slow queries: 0 Opens: 76 Flush tables: 1
> Open
> tables: 7
> --------------
>
> This gives me the port number (3306) from a TCP/IP connection.
>
> However, on my Internet Provider's Solaris computer, the UNIX Sockets
> are given instead (/tmp/mysql.sock) with no ports specified.
>
>
> mysql Ver 9.27 Distrib 3.22.13-beta, for sun-solaris2.6 (sparc)
>
> Connection id: 289
> Current database: hollyer
> Current user: tr003073@localhost
> Server version 3.22.13-beta
> Protocol version 10
> Connection Localhost via UNIX socket
> UNIX socket /tmp/mysql.sock
> Uptime: 9 days 6 hours 57 min 8 sec
>
> Threads: 3 Questions: 2949 Slow queries: 0 Opens: 265 Flush
tables:
> 1 Open
> tables: 62
> --------------
>
> How do I find out to which port number I need to connect?
>
> Do I have to use UNIX Sockets in my application code? I have
> tried using /tmp/mysql.socket in my ViewDB.java application as
> part of the JDBC connection but received the following error.
>
> // force loading of the jdbc.odbc Driver
> Class.forName("org.gjt.mm.mysql.Driver");
>
>
> // connect to the database
> mmCon = DriverManager.getConnection(
> "jdbc:mysql://localhost:/tmp/mysql.sock/databaseName",
> "user","pass"); // ** note /tmp/mysql/sock for Port
Number
> // ** obviously will give a
> // ** NumberFormatException because
> the code
> // ** is expecting a Port number
> instead of
> // ** /tmp/mysql.sock
>
> // create Statements
> myStmt = mmCon.createStatement();
>
> Indeed a NumberFormatException is given:
>
> java.lang.NumberFormatException: /
> at java.lang.Throwable.<init>(Compiled Code)
> at java.lang.Exception.<init>(Compiled Code)
> at java.lang.RuntimeException.<init>(Compiled Code)
> at java.lang.IllegalArgumentException.<init>(Compiled Code)
> at java.lang.NumberFormatException.<init>(Compiled Code)
> at java.lang.Integer.parseInt(Compiled Code)
> at java.lang.Integer.parseInt(Compiled Code)
> at org.gjt.mm.mysql.Driver.port(Compiled Code)
> at org.gjt.mm.mysql.Driver.connect(Compiled Code)
> at java.sql.DriverManager.getConnection(Compiled Code)
> at java.sql.DriverManager.getConnection(Compiled Code)
> at ViewDB.<init>(Compiled Code)
> at ViewDB.main(Compiled Code)
>
> Conversely, when I substitute the default port on my Windows NT machine
when
> trying
> to get a Connection, a NullPointerException is given. Most likely because
I
> have not
> connected to the right Port.
>
> So do I connect to the server using code like the following to establish a
> port?
>
> Socket s = new Socket("localhost/tmp/mysql.sock", 3306); //????????
>
>
> Any help with the above would be greatly appreciated.
>
>
> Martin Hollyer
>
>
>