Can't get JDBC to work from Java to MySQL

T

tomzam

I try not to multipost but I tried this post over at comp.lang.mysql
and no takers over there.
I just can't figure whats wrong here,
I'm using Java 1.4 on Fedora Linux and of course MySql.
I'm doing a simple database read but I'm getting errors anyway.
I've listed the Table, The Java code, and the stack trace below.

Post follows:
I suspect the error is possibly different character ets between java
and mysql but don't know what to do about it.

I have the TABLE

describe MEGAMILLION;
+----------------+-------------+------+-----+---------+----------------
+
| Field | Type | Null | Key | Default | Extra
|
+----------------+-------------+------+-----+---------+----------------
+
| mega_id | int(11) | NO | PRI | NULL | auto_increment
|
| draw_date | date | YES | | NULL |
|
| ball_1 | smallint(6) | YES | | NULL |
|
| ball_2 | smallint(6) | YES | | NULL |
|
| ball_3 | smallint(6) | YES | | NULL |
|
| ball_4 | smallint(6) | YES | | NULL |
|
| ball_5 | smallint(6) | YES | | NULL |
|
| mega_ball | smallint(6) | YES | | NULL |
|
| digit_sum | int(11) | YES | | NULL |
|
| day_flag | smallint(6) | YES | | NULL |
|
| next_door_flag | smallint(6) | YES | | NULL |
|
+----------------+-------------+------+-----+---------+----------------
+

Which I am trying to read with the following Java Code:

package com.tomzamm98;

import java.sql.*;

public class Base {


static final long serialVersionUID = 1000000L;

public static void main(String args[]) {
Base work = new Base();
work.myConnect();
}

public Base() {
System.out.println("compiles and prints!");
}

public void myConnect() {
try {
//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Class.forName("com.mysql.jdbc.Driver");
}
catch(ClassNotFoundException e) {
System.out.println("Unable to load Driver class");
System.out.println("Reason why: " + e.getMessage());
return; } // end of first try
// database commands below here

try {
Connection con = DriverManager.getConnection("jdbc:mysql://
localhost/LOTTO","tomzam","");
Statement stat = con.createStatement();
ResultSet rs = stat.executeQuery("SELECT draw_date FROM
MEGAMILLION");
while (rs.next()) {
System.out.println((int) rs.getInt("ball_1"));
}
rs.close();
stat.close();
con.close();

}
catch(SQLException se) {
System.out.println("SQL Exception:" + se.getMessage());
se.printStackTrace(System.out);

} // end of second try

}
} //end of Base class

but I get this stack trace:


SQL Exception:Unexpected exception encountered during query.
java.sql.SQLException: Unexpected exception encountered during query.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2593)
at com.mysql.jdbc.ConnectionImpl.configureClientCharacterSet
(ConnectionImpl.java:1768)
at com.mysql.jdbc.ConnectionImpl.initializePropsFromServer
(ConnectionImpl.java:3444)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:
2062)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:723)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:
298)
at com.mysql.jdbc.NonRegisteringDriver.connect
(NonRegisteringDriver.java:282)
at java.sql.DriverManager.getConnection(libgcj.so.7rh)
at java.sql.DriverManager.getConnection(libgcj.so.7rh)
at com.tomzammi98.Base.myConnect(Base.java:31)
at com.tomzammi98.Base.main(Base.java:12)
Caused by: java.io.CharConversionException
at gnu.gcj.convert.Input_iconv.read(libgcj.so.7rh)
at java.lang.String.init(libgcj.so.7rh)
at java.lang.String.<init>(libgcj.so.7rh)
at com.mysql.jdbc.SingleByteCharsetConverter.<init>
(SingleByteCharsetConverter.java:152)
at com.mysql.jdbc.SingleByteCharsetConverter.initCharset
(SingleByteCharsetConverter.java:107)
at com.mysql.jdbc.SingleByteCharsetConverter.getInstance
(SingleByteCharsetConverter.java:85)
at com.mysql.jdbc.ConnectionImpl.getCharsetConverter
(ConnectionImpl.java:2773)
at com.mysql.jdbc.StringUtils.getBytes(StringUtils.java:679)
at com.mysql.jdbc.Buffer.writeStringNoNull(Buffer.java:663)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2049)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2548)
...10 more

The error seems to be from the execute query line of Java.

So, what is wrong with my java, my mysql, or both?
I've been at it for a while now, and am getting tired.
So, any help will be appreciated.
Thanks
- Tom Z
 
D

Donkey Hottie

(e-mail address removed) wrote in @r36g2000prf.googlegroups.com:

ResultSet rs = stat.executeQuery("SELECT draw_date FROM
MEGAMILLION");
while (rs.next()) {
System.out.println((int) rs.getInt("ball_1"));
}

1) You ask for Date 'draw_date'
2) but process int 'ball_1'

Until you get this straight, I will not bother to compile the code myself.
 
T

tomzam

(e-mail address removed) wrote in @r36g2000prf.googlegroups.com:

ResultSet rs = stat.executeQuery("SELECT draw_date FROM


1) You ask for Date 'draw_date'
2) but process int 'ball_1'

Until you get this straight, I will not bother to compile the code myself.

Sorry about the Java code being out of sink, it was because of
multiple attempts to
fix the problem.
(also, I originally tried to get answer from comp.databases.mysql nto
comp.lang.mysql - shows
what happens when one is tired)

But no excuses:

I still would like your help and have pasted and copyied everything
here:
(Java, Stack trace, and table description - stack trace from the code
listed below here)

package com.tomzammikiel98;

import java.sql.*;

public class Base {


static final long serialVersionUID = 1000000L;

public static void main(String args[]) {
Base work = new Base();
work.myConnect();
}

public Base() {
System.out.println("compiles and prints!");
}

public void myConnect() {
try {
//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Class.forName("com.mysql.jdbc.Driver");
}
catch(ClassNotFoundException e) {
System.out.println("Unable to load Driver class");
System.out.println("Reason why: " + e.getMessage());
return; } // end of first try
// database commands below here

try {
Connection con = DriverManager.getConnection("jdbc:mysql://
localhost/LOTTO","tomzam","");
Statement stat = con.createStatement();
ResultSet rs = stat.executeQuery("SELECT ball_1 FROM
MEGAMILLION");
while (rs.next()) {
System.out.println((int) rs.getInt("ball_1"));
}
rs.close();
stat.close();
con.close();

java com.tomzammikiel98.Base
compiles and prints!
SQL Exception:Unexpected exception encountered during query.
java.sql.SQLException: Unexpected exception encountered during query.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2593)
at com.mysql.jdbc.ConnectionImpl.configureClientCharacterSet
(ConnectionImpl.java:1768)
at com.mysql.jdbc.ConnectionImpl.initializePropsFromServer
(ConnectionImpl.java:3444)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:
2062)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:723)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:
298)
at com.mysql.jdbc.NonRegisteringDriver.connect
(NonRegisteringDriver.java:282)
at java.sql.DriverManager.getConnection(libgcj.so.7rh)
at java.sql.DriverManager.getConnection(libgcj.so.7rh)
at com.tomzammikiel98.Base.myConnect(Base.java:31)
at com.tomzammikiel98.Base.main(Base.java:12)
Caused by: java.io.CharConversionException
at gnu.gcj.convert.Input_iconv.read(libgcj.so.7rh)
at java.lang.String.init(libgcj.so.7rh)
at java.lang.String.<init>(libgcj.so.7rh)
at com.mysql.jdbc.SingleByteCharsetConverter.<init>
(SingleByteCharsetConverter.java:152)
at com.mysql.jdbc.SingleByteCharsetConverter.initCharset
(SingleByteCharsetConverter.java:107)
at com.mysql.jdbc.SingleByteCharsetConverter.getInstance
(SingleByteCharsetConverter.java:85)
at com.mysql.jdbc.ConnectionImpl.getCharsetConverter
(ConnectionImpl.java:2773)
at com.mysql.jdbc.StringUtils.getBytes(StringUtils.java:679)
at com.mysql.jdbc.Buffer.writeStringNoNull(Buffer.java:663)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2049)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2548)
...10 more



}
catch(SQLException se) {
System.out.println("SQL Exception:" + se.getMessage());
se.printStackTrace(System.out);

} // end of second try

}
} //end of Base class


$java com.tomzammikiel98.Base
compiles and prints!
SQL Exception:Unexpected exception encountered during query.
java.sql.SQLException: Unexpected exception encountered during query.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2593)
at com.mysql.jdbc.ConnectionImpl.configureClientCharacterSet
(ConnectionImpl.java:1768)
at com.mysql.jdbc.ConnectionImpl.initializePropsFromServer
(ConnectionImpl.java:3444)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:
2062)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:723)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:
298)
at com.mysql.jdbc.NonRegisteringDriver.connect
(NonRegisteringDriver.java:282)
at java.sql.DriverManager.getConnection(libgcj.so.7rh)
at java.sql.DriverManager.getConnection(libgcj.so.7rh)
at com.tomzammikiel98.Base.myConnect(Base.java:31)
at com.tomzammikiel98.Base.main(Base.java:12)
Caused by: java.io.CharConversionException
at gnu.gcj.convert.Input_iconv.read(libgcj.so.7rh)
at java.lang.String.init(libgcj.so.7rh)
at java.lang.String.<init>(libgcj.so.7rh)
at com.mysql.jdbc.SingleByteCharsetConverter.<init>
(SingleByteCharsetConverter.java:152)
at com.mysql.jdbc.SingleByteCharsetConverter.initCharset
(SingleByteCharsetConverter.java:107)
at com.mysql.jdbc.SingleByteCharsetConverter.getInstance
(SingleByteCharsetConverter.java:85)
at com.mysql.jdbc.ConnectionImpl.getCharsetConverter
(ConnectionImpl.java:2773)
at com.mysql.jdbc.StringUtils.getBytes(StringUtils.java:679)
at com.mysql.jdbc.Buffer.writeStringNoNull(Buffer.java:663)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2049)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2548)
...10 more
describe MEGAMILLION;
+----------------+-------------+------+-----+---------+----------------
+
| Field | Type | Null | Key | Default | Extra
|
+----------------+-------------+------+-----+---------+----------------
+
| mega_id | int(11) | NO | PRI | NULL | auto_increment
|
| draw_date | date | YES | | NULL |
|
| ball_1 | smallint(6) | YES | | NULL |
|
| ball_2 | smallint(6) | YES | | NULL |
|
| ball_3 | smallint(6) | YES | | NULL |
|
| ball_4 | smallint(6) | YES | | NULL |
|
| ball_5 | smallint(6) | YES | | NULL |
|
| mega_ball | smallint(6) | YES | | NULL |
|
| digit_sum | int(11) | YES | | NULL |
|
| day_flag | smallint(6) | YES | | NULL |
|
| next_door_flag | smallint(6) | YES | | NULL |
|
+----------------+-------------+------+-----+---------+----------------
+
11 rows in set (0.03 sec)

any help still appeciated,

- Tom Z
 
D

Dave Miller

(e-mail address removed) wrote in @r36g2000prf.googlegroups.com:

ResultSet rs = stat.executeQuery("SELECT draw_date FROM

1) You ask for Date 'draw_date'
2) but process int 'ball_1'

Until you get this straight, I will not bother to compile the code myself.

Sorry about the Java code being out of sink, it was because of
multiple attempts to
fix the problem.
(also, I originally tried to get answer from comp.databases.mysql nto
comp.lang.mysql - shows
what happens when one is tired)

But no excuses:

I still would like your help and have pasted and copyied everything
here:
(Java, Stack trace, and table description - stack trace from the code
listed below here)

package com.tomzammikiel98;

import java.sql.*;

public class Base {


static final long serialVersionUID = 1000000L;

public static void main(String args[]) {
Base work = new Base();
work.myConnect();
}

public Base() {
System.out.println("compiles and prints!");
}

public void myConnect() {
try {
//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Class.forName("com.mysql.jdbc.Driver");
}
catch(ClassNotFoundException e) {
System.out.println("Unable to load Driver class");
System.out.println("Reason why: " + e.getMessage());
return; } // end of first try
// database commands below here

try {
Connection con = DriverManager.getConnection("jdbc:mysql://
localhost/LOTTO","tomzam","");
Statement stat = con.createStatement();
ResultSet rs = stat.executeQuery("SELECT ball_1 FROM
MEGAMILLION");
while (rs.next()) {
System.out.println((int) rs.getInt("ball_1"));
}
rs.close();
stat.close();
con.close();

java com.tomzammikiel98.Base
compiles and prints!
SQL Exception:Unexpected exception encountered during query.
java.sql.SQLException: Unexpected exception encountered during query.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2593)
at com.mysql.jdbc.ConnectionImpl.configureClientCharacterSet
(ConnectionImpl.java:1768)
at com.mysql.jdbc.ConnectionImpl.initializePropsFromServer
(ConnectionImpl.java:3444)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:
2062)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:723)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:
298)
at com.mysql.jdbc.NonRegisteringDriver.connect
(NonRegisteringDriver.java:282)
at java.sql.DriverManager.getConnection(libgcj.so.7rh)
at java.sql.DriverManager.getConnection(libgcj.so.7rh)
at com.tomzammikiel98.Base.myConnect(Base.java:31)
at com.tomzammikiel98.Base.main(Base.java:12)
Caused by: java.io.CharConversionException
at gnu.gcj.convert.Input_iconv.read(libgcj.so.7rh)
at java.lang.String.init(libgcj.so.7rh)
at java.lang.String.<init>(libgcj.so.7rh)
at com.mysql.jdbc.SingleByteCharsetConverter.<init>
(SingleByteCharsetConverter.java:152)
at com.mysql.jdbc.SingleByteCharsetConverter.initCharset
(SingleByteCharsetConverter.java:107)
at com.mysql.jdbc.SingleByteCharsetConverter.getInstance
(SingleByteCharsetConverter.java:85)
at com.mysql.jdbc.ConnectionImpl.getCharsetConverter
(ConnectionImpl.java:2773)
at com.mysql.jdbc.StringUtils.getBytes(StringUtils.java:679)
at com.mysql.jdbc.Buffer.writeStringNoNull(Buffer.java:663)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2049)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2548)
...10 more



}
catch(SQLException se) {
System.out.println("SQL Exception:" + se.getMessage());
se.printStackTrace(System.out);

} // end of second try

}
} //end of Base class


$java com.tomzammikiel98.Base
compiles and prints!
SQL Exception:Unexpected exception encountered during query.
java.sql.SQLException: Unexpected exception encountered during query.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2593)
at com.mysql.jdbc.ConnectionImpl.configureClientCharacterSet
(ConnectionImpl.java:1768)
at com.mysql.jdbc.ConnectionImpl.initializePropsFromServer
(ConnectionImpl.java:3444)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:
2062)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:723)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:
298)
at com.mysql.jdbc.NonRegisteringDriver.connect
(NonRegisteringDriver.java:282)
at java.sql.DriverManager.getConnection(libgcj.so.7rh)
at java.sql.DriverManager.getConnection(libgcj.so.7rh)
at com.tomzammikiel98.Base.myConnect(Base.java:31)
at com.tomzammikiel98.Base.main(Base.java:12)
Caused by: java.io.CharConversionException
at gnu.gcj.convert.Input_iconv.read(libgcj.so.7rh)
at java.lang.String.init(libgcj.so.7rh)
at java.lang.String.<init>(libgcj.so.7rh)
at com.mysql.jdbc.SingleByteCharsetConverter.<init>
(SingleByteCharsetConverter.java:152)
at com.mysql.jdbc.SingleByteCharsetConverter.initCharset
(SingleByteCharsetConverter.java:107)
at com.mysql.jdbc.SingleByteCharsetConverter.getInstance
(SingleByteCharsetConverter.java:85)
at com.mysql.jdbc.ConnectionImpl.getCharsetConverter
(ConnectionImpl.java:2773)
at com.mysql.jdbc.StringUtils.getBytes(StringUtils.java:679)
at com.mysql.jdbc.Buffer.writeStringNoNull(Buffer.java:663)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2049)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2548)
...10 more
describe MEGAMILLION;
+----------------+-------------+------+-----+---------+----------------
+
| Field | Type | Null | Key | Default | Extra
|
+----------------+-------------+------+-----+---------+----------------
+
| mega_id | int(11) | NO | PRI | NULL | auto_increment
|
| draw_date | date | YES | | NULL |
|
| ball_1 | smallint(6) | YES | | NULL |
|
| ball_2 | smallint(6) | YES | | NULL |
|
| ball_3 | smallint(6) | YES | | NULL |
|
| ball_4 | smallint(6) | YES | | NULL |
|
| ball_5 | smallint(6) | YES | | NULL |
|
| mega_ball | smallint(6) | YES | | NULL |
|
| digit_sum | int(11) | YES | | NULL |
|
| day_flag | smallint(6) | YES | | NULL |
|
| next_door_flag | smallint(6) | YES | | NULL |
|
+----------------+-------------+------+-----+---------+----------------
+
11 rows in set (0.03 sec)

any help still appeciated,

- Tom Z
Try rs.getShort("ball_1") which maps closer. If you still get the same
stack trace, try asking for one of the int columns to eliminate data
conversion as the error.
 
D

Donkey Hottie

(e-mail address removed) wrote in

Sorry about the Java code being out of sink, it was because of
multiple attempts to
fix the problem.
(also, I originally tried to get answer from comp.databases.mysql nto
comp.lang.mysql - shows
what happens when one is tired)

But no excuses:

I still would like your help and have pasted and copyied everything
here:
(Java, Stack trace, and table description - stack trace from the code
listed below here)

Okay. I build a database on my MySQL according what you wrote, then copied
your code to my Netbeans, and ran it.

No problems whatsover.

I have the latest MySQL driver. I did this on Java 6 on a late MySQL.

You mentioned Java 1.4.2... Maybe your MySQL driver is not compatibe with
1.4.2?I don't know.

But basically your code is ok.

No problems in my setup.
 
L

Lew

package com.tomzammikiel98;

import java.sql.*;

public class Base {

    static final long serialVersionUID = 1000000L;

    public static void main(String args[]) {
       Base work = new Base();
       work.myConnect();
    }

    public Base() {
    System.out.println("compiles and prints!");
    }

    public void myConnect() {
        try {
            //Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
         Class.forName("com.mysql.jdbc.Driver");
        }

Don't load the driver class over and over again. Do it in a static
initializer block.

....
Caused by: java.io.CharConversionException
   at gnu.gcj.convert.Input_iconv.read(libgcj.so.7rh)

What happens if you use a real Java implementation?

Also, are you aware that Java 1.4 is obsolete?
 
A

Arne Vajhøj

try {
//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Class.forName("com.mysql.jdbc.Driver");
}
catch(ClassNotFoundException e) {
System.out.println("Unable to load Driver class");
System.out.println("Reason why: " + e.getMessage());
return; } // end of first try
// database commands below here

try {
Connection con = DriverManager.getConnection("jdbc:mysql://
localhost/LOTTO","tomzam","");
Statement stat = con.createStatement();
ResultSet rs = stat.executeQuery("SELECT ball_1 FROM
MEGAMILLION");
while (rs.next()) {
System.out.println((int) rs.getInt("ball_1"));
}
rs.close();
stat.close();
con.close();
SQL Exception:Unexpected exception encountered during query.
java.sql.SQLException: Unexpected exception encountered during query.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2593)
at com.mysql.jdbc.ConnectionImpl.configureClientCharacterSet
(ConnectionImpl.java:1768)
at com.mysql.jdbc.ConnectionImpl.initializePropsFromServer
(ConnectionImpl.java:3444)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:
2062)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:723)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:
298)
at com.mysql.jdbc.NonRegisteringDriver.connect
(NonRegisteringDriver.java:282)
at java.sql.DriverManager.getConnection(libgcj.so.7rh)
Caused by: java.io.CharConversionException
at gnu.gcj.convert.Input_iconv.read(libgcj.so.7rh)
at java.lang.String.init(libgcj.so.7rh)
at java.lang.String.<init>(libgcj.so.7rh)
at com.mysql.jdbc.SingleByteCharsetConverter.<init>
(SingleByteCharsetConverter.java:152)
at com.mysql.jdbc.SingleByteCharsetConverter.initCharset
(SingleByteCharsetConverter.java:107)
at com.mysql.jdbc.SingleByteCharsetConverter.getInstance
(SingleByteCharsetConverter.java:85)
at com.mysql.jdbc.ConnectionImpl.getCharsetConverter
(ConnectionImpl.java:2773)
at com.mysql.jdbc.StringUtils.getBytes(StringUtils.java:679)
at com.mysql.jdbc.Buffer.writeStringNoNull(Buffer.java:663)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2049)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2548)

I believe that you should try installing SUN Java (and why not
latest 1.6.0) and then test again with it.

It very much looks like a GCJ compatibility issue.

Arne
 
T

tomzam

I believe that you should try installing SUN Java (and why not
latest 1.6.0) and then test again with it.

It very much looks like a GCJ compatibility issue.

Arne

Thank you Arne ( and everyone else) it was a compatability issue.
Using the JRE for java 1.6 worked like a charm. (The program runs
without exceptions)
I quess I'll have to drag myself into the present and use a current
version of Java!

Thanks everyone again.
-Tom Z

p.s. I'll move the code for the driver into a static initializer as
suggested by one of the posters.
 
A

Arne Vajhøj

it was a compatability issue.
Using the JRE for java 1.6 worked like a charm. (The program runs
without exceptions)
I quess I'll have to drag myself into the present and use a current
version of Java!

GCJ is not very attractive.

Arne
 
L

Lew

It isn't so much that your version was old, though it is, but that, as Arne
pointed out,
GCJ is not very attractive.

I have seen continuing and unrelenting evidence for years that GCJ is all but
useless, a bit surprising considering how good the rest of the Gnu compiler
collection is. The combination of GCC's C/C++, gmake, gdb and emacs is a
tremendous IDE. Alas, not so for Java.
 
R

Roedy Green

a Code:
package com.tomzamm98;

import java.sql.*;

public class Base {


static final long serialVersionUID = 1000000L;

public static void main(String args[]) {
Base work = new Base();
work.myConnect();
}

public Base() {
System.out.println("compiles and prints!");
}

public void myConnect() {
try {
Class.forName("com.mysql.jdbc.Driver");
}
catch(ClassNotFoundException e) {
System.out.println("Unable to load Driver class");
System.out.println("Reason why: " + e.getMessage());
return; } // end of first try
// database commands below here

try {
Connection con = DriverManager.getConnection("jdbc:mysql://
localhost/LOTTO","tomzam","");
Statement stat = con.createStatement();
ResultSet rs = stat.executeQuery("SELECT draw_date FROM
MEGAMILLION");
while (rs.next()) {
System.out.println((int) rs.getInt("ball_1"));
}
rs.close();
stat.close();
con.close();

}
catch(SQLException se) {
System.out.println("SQL Exception:" + se.getMessage());
se.printStackTrace(System.out);

} // end of second try

}
} //end of Base class

at com.mysql.jdbc.NonRegisteringDriver.connect
(NonRegisteringDriver.java:282)

Here is the code I suggest for logging in to SQL at
http://mindprod.com/jgloss/jdbc.html

Connecting to a MySQL database via JDBC

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

private Connection conn;

public void init()
{
// instantiate the MySQL JDBC driver. Using
ClassForName/newInstance
// rather than new means the driver need not be present at compile
time.
// Oddly, we need not retain a reference to the Driver object,
// or even do a newInstance().

try
{
Class.forName( "com.mysql.jdbc.Driver" ));
}
catch ( Exception e )
{
System.out.println( "can't load MySQL driver: " + e.getMessage()
);
}
try
{
// log on to the allaboutsquirrels database
conn = DriverManager.getConnection(
"jdbc:mysql://localhost/allaboutsquirrels", "myuserid", "mypassword"
);
}
catch ( SQLException e )
{
System.out.println( "can't connect to MySQL: " + e.getMessage()
);
}
}
....

// create the shell into which you can pour an SQL command.
Statement stmt = conn.createStatement();

Make sure you have your userid/password, case sensitive.

Sun bought out MySQL. Perhaps they changed the driver name to
something Sunny.
--
Roedy Green Canadian Mind Products
http://mindprod.com
PM Steven Harper is fixated on the costs of implementing Kyoto, estimated as high as 1% of GDP.
However, he refuses to consider the costs of not implementing Kyoto which the
famous economist Nicholas Stern estimated at 5 to 20% of GDP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,034
Messages
2,570,356
Members
47,002
Latest member
RobertoLip

Latest Threads

Top