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
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