> DriverManager.getConnection("jdbc:mysql:///mydbname?user=myusername&password=mypassword&useUnicode=true&characterEncoding=utf-8");
> // The above, unfortunately, is generating a
> NullPointerException

Signature
Lothar Kimmeringer E-Mail: spamfang@kimmeringer.de
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)
Always remember: The answer is forty-two, there can only be wrong
questions!
Richard Schulman:
>>DriverManager.getConnection("jdbc:mysql:///mydbname?user=myusername&password=mypassword&useUnicode=true&characterEncoding=utf-8");
>> // The above, unfortunately, is generating a
>> NullPointerException
Lothar Kimmeringer:
>Where's the server-ip? The URL should look like this:
>jdbc:mysql://127.0.0.1:3306/mydbname
>(if the database is running on the same system listening on port
>3306.
Thanks for your interest, Lothar.
Actually, the URL of 127.0.0.1:3306 doesn't need to be included, since
it is the default. But just to be sure, I inserted the URL and
recompiled: the same NullPointerException message occured.
Any other suggestions?
For those who may have missed my earlier post, here again is the
source code, environmental information, and error message at run time:
Environment: MySQL database 5.0.21-community-nt, MySQL Client version
5.0.11, MS XP Home with Service Pack 2, mysql-connector-java-3.1.13,
Unicode database.
The classpath set before running the application is:
SET
CLASSPATH=.;c:\mysql-connector-java-3.1.13\mysql-connector-java-3.1.13-bin.jar
Here is the program. (It's not intended to do anything but
successfully access the database.):
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Test2
{
public static void main(String[] args)
{
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try
{
// The newInstance() call is a work around for some
// broken Java implementations
Class.forName("com.mysql.jdbc.Driver").newInstance();
}
catch (Exception ex)
{
System.out.println("Error location #1");
System.out.println("SQLException: " +
ex.getMessage());
}
try
{
conn =
DriverManager.getConnection("jdbc:mysql:///mydbname?user=myusername&password=mypassword&useUnicode=true&characterEncoding=utf-8");
// The above, unfortunately, is generating a
NullPointerException
}
catch (SQLException ex)
{
// handle any errors
System.out.println("Error location #2");
System.out.println("SQLException: " +
ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " +
ex.getErrorCode());
}
// assume that conn is an already created JDBC connection
try
{
stmt = conn.createStatement();
}
catch (SQLException ex)
{
System.out.println("Error location #3");
System.out.println("SQLException: " +
ex.getMessage());
}
try
{
rs = stmt.executeQuery("SELECT count(*) from poets");
System.out.println("The query apparently executed");
}
catch (SQLException ex)
{
System.out.println("Error location #4");
System.out.println("SQLException: " +
ex.getMessage());
}
/* or alternatively, if you don't know ahead of time that
the query will be a SELECT...
if (stmt.execute("SELECT count(*) from poets"))
jdbc:mysql:///chinese?user=root&password=lqi5B
rs = stmt.getResultSet();
Now do something with the ResultSet ....
*/
finally
{
// it is a good idea to release resources in a
finally{} block
// in reverse-order of their creation if they are
no-longer needed
if (rs != null)
{
try
{
rs.close();
}
catch (SQLException sqlEx)
{ // ignore }
rs = null;
}
}
if (stmt != null)
{
try
{
stmt.close();
}
catch (SQLException sqlEx)
{ // ignore }
stmt = null;
}
}
}
}
}
Richard Schulman (To email me, remove the 'xx' from the reply
address.)
IchBin - 19 Aug 2006 06:35 GMT
> Richard Schulman:
>>> DriverManager.getConnection("jdbc:mysql:///mydbname?user=myusername&password=mypassword&useUnicode=true&characterEncoding=utf-8");
[quoted text clipped - 140 lines]
> Richard Schulman (To email me, remove the 'xx' from the reply
> address.)
The connect statement I use look s like this:
Connection con = DriverManager.getConnection(
"jdbc:mysql://localhost/targetDB",
MYSQL_LOGINID,
MYSQL_LOGINPSWD
);
--
Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Richard Schulman - 20 Aug 2006 21:28 GMT
> Connection con = DriverManager.getConnection(
> "jdbc:mysql://localhost/targetDB",
> MYSQL_LOGINID,
> MYSQL_LOGINPSWD
> );
You must define those two variables somewhere: otherwise, all you'll
get is a compiler error -- unrecognized variables.
Richard Schulman (For email reply, please remove the antispamming 'xx' characters.)
IchBin - 21 Aug 2006 06:11 GMT
>> Connection con = DriverManager.getConnection(
>> "jdbc:mysql://localhost/targetDB",
[quoted text clipped - 5 lines]
> get is a compiler error -- unrecognized variables.
> Richard Schulman (For email reply, please remove the antispamming 'xx' characters.)
That is correct. They are defined as CONSTANTS here. My assumption is:
that is what they would be recognized as...
--
Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)