Re: Can't get JDBC to work from Java to MySQL
- From: Dave Miller <nonregistered@xxxxxxxxxxxx>
- Date: Wed, 17 Dec 2008 21:18:16 GMT
tomzam@xxxxxxxxx wrote:
On Dec 17, 2:04 pm, Donkey Hottie <s...@xxxxxxxxxxxxxx> wrote: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.tom...@xxxxxxxxx wrote in news:f4deb91b-2e9c-431d-8f8e-efd7297c8639
@r36g2000prf.googlegroups.com:
ResultSet rs = stat.executeQuery("SELECT draw_date FROM
MEGAMILLION");1) You ask for Date 'draw_date'
while (rs.next()) {
System.out.println((int) rs.getInt("ball_1"));
}
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
--
Dave Miller
Java Web Hosting
http://www.cheap-jsp-hosting.com/
.
- References:
- Can't get JDBC to work from Java to MySQL
- From: tomzam
- Re: Can't get JDBC to work from Java to MySQL
- From: Donkey Hottie
- Re: Can't get JDBC to work from Java to MySQL
- From: tomzam
- Can't get JDBC to work from Java to MySQL
- Prev by Date: Re: Can't get JDBC to work from Java to MySQL
- Next by Date: Re: compare two byte[] 's
- Previous by thread: Re: Can't get JDBC to work from Java to MySQL
- Next by thread: Re: Can't get JDBC to work from Java to MySQL
- Index(es):
Relevant Pages
|