Re: Can't get JDBC to work from Java to MySQL



tomzam@xxxxxxxxx wrote:
On Dec 17, 2:04 pm, Donkey Hottie <s...@xxxxxxxxxxxxxx> wrote:
tom...@xxxxxxxxx wrote in news:f4deb91b-2e9c-431d-8f8e-efd7297c8639
@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.

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.

--
Dave Miller
Java Web Hosting
http://www.cheap-jsp-hosting.com/
.



Relevant Pages

  • Re: data type error in my query
    ... the resultset returned the same value for comments. ... FROM dbo.tblWeblog as W1 LEFT OUTER JOIN dbo.tblUserComments as C ... > If blogID is a unique identifier for rows of tblWeblog, ... If I strip out W.blogComment the query runs fine. ...
    (microsoft.public.sqlserver.programming)
  • Re: When do selects execute for multiple resultsets
    ... SQL Server executes each query and stops when its ... When the first resultset is ... The CommandTimeout is measured from the time you execute the query until the ...
    (microsoft.public.dotnet.framework.adonet)
  • refreshing a window
    ... the query is processed, the results do not come up at the bottom until ... private JTextField output, input, input1, input2, input3; ... ResultSet resultSet; ...
    (comp.lang.java.programmer)
  • Re: Cant get JDBC to work from Java to MySQL
    ... ResultSet rs = stat.executeQuery("SELECT draw_date FROM ... (Java, Stack trace, and table description - stack trace from the code ... compiles and prints! ... SQL Exception:Unexpected exception encountered during query. ...
    (comp.lang.java.programmer)
  • Re: Group By
    ... If you are looking to do the eqivalent of a GROUP BY in a SELECT query ... resultset and issue queries using the QueryADataSet assembly. ... > I could solve this using multiple queries and differnt filters, ...
    (microsoft.public.dotnet.framework.adonet)