Hi everyone,
I got an error, when i tried to connect mysql with java. Any
suggestions ?
Thank you.
Bug Report
==========
OS : RedHat Fedora Core 6
JSDK version : javac 1.5.0_12 [Linux version]
MySQL version : mysql Ver 14.12 Distrib 5.0.22, for redhat-linux-gnu
(i686) using readline 5.0
MySQL/JConnector version : mysql-connector-java-5.0.7
Query used for creating the db
==============================
drop database movies;
create database movies;
use movies;
create table movie (
id int not null auto_increment,
title varchar(50),
year int,
price decimal(8,2),
primary key(id)
);
insert into movie (title,year,price)
values("FirstMovie",1901,14.95);
insert into movie (title,year,price)
values("SecondMovie",1902,15.33);
Java code
=========
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Test
{
public static void main(String[] args)
{
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
System.out.println("Registering Driver...[OK]");
}
catch(Exception ex)
{
System.out.println("Cannot register the driver");
}
try
{
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost/
movies?"+"user=thushanthan&password=phpmysql");
System.out.println("Establishing Connection...[OK]");
}
catch(SQLException ex)
{
System.out.println("SQLException: "+ex.getMessage());
System.out.println("SQLState: "+ex.getSQLState());
System.out.println("VendorError: "+ex.getErrorCode());
}
}
}
Error
=====
Registering Driver...[OK]
SQLException: Error during query: Unexpected Exception:
java.io.CharConversionException message given: null
Nested Stack Trace:
** BEGIN NESTED EXCEPTION **
java.io.CharConversionException
STACKTRACE:
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:
153)
at
com.mysql.jdbc.SingleByteCharsetConverter.initCharset(SingleByteCharsetConverter.java:
108)
at
com.mysql.jdbc.SingleByteCharsetConverter.getInstance(SingleByteCharsetConverter.java:
86)
at com.mysql.jdbc.Connection.getCharsetConverter(Connection.java:
3478)
at com.mysql.jdbc.StringUtils.getBytes(StringUtils.java:615)
at com.mysql.jdbc.Buffer.writeStringNoNull(Buffer.java:655)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1686)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3250)
at
com.mysql.jdbc.Connection.configureClientCharacterSet(Connection.java:
2514)
at
com.mysql.jdbc.Connection.initializePropsFromServer(Connection.java:
4112)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2762)
at com.mysql.jdbc.Connection.<init>(Connection.java:1553)
at
com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:
285)
at java.sql.DriverManager.getConnection(libgcj.so.7rh)
at java.sql.DriverManager.getConnection(libgcj.so.7rh)
at Test.main(Test.java:25)
** END NESTED EXCEPTION **
SQLState: S1000
VendorError: 0
HP - 25 Sep 2007 11:36 GMT
Op Mon, 24 Sep 2007 23:44:24 -0700, tikte thushianthan15:
> Hi everyone,
>
> I got an error, when i tried to connect mysql with java. suggestions?
You use Eclipse? I got (and still have) similar problems with respect to
BIRT - bugzilla integration into Eclipse. But in your case i would first
try the JConnector version 3.14 insteadof 5.0.... you can find it at the
mysql website
> OS : RedHat Fedora Core 6
>
[quoted text clipped - 4 lines]
>
> MySQL/JConnector version : mysql-connector-java-5.0.7
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Signature
groet, HP
http://www.industrial-tsi.com
Eclipse RCP training >>>> http://tinyurl.com/3d7ngo
Jyrki O Saarinen - 25 Sep 2007 13:20 GMT
: 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:
The gcj (gcc java runtime) doesn't seem to handle character set
conversions in the way that the MySQL driver requires. Try using normal
JDK for building and running your application.
Roedy Green - 26 Sep 2007 11:33 GMT
>I got an error, when i tried to connect mysql with java. Any
>suggestions ?
see the sample code at http://mindprod.com/jgloss/jdbc.html#CONNECTING

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
AL - 14 Nov 2007 22:42 GMT
>> I got an error, when i tried to connect mysql with java. Any
>> suggestions ?
> see the sample code at http://mindprod.com/jgloss/jdbc.html#CONNECTING
That was helpful to me - after failing to "upsize" my older Access
database to SQL Server I decided to connect to the Access DB via
jdbc-odbc. I did have to change one line of code in the example that
was causing me a problem.
An excerpt from your page shows:
private static final String URL = "jdbc:odbc:";
<snip>
private static String getConnectionUrl()
{
return URL + ":" + DATABASENAME;
}
The ":" needs to be removed from the concatenation. I'm fairly new to
Java so it took me a while to discover why my connection kept failing.
Thought you'd like to know.
Thanks for all your advice to this group.
AL
Roedy Green - 26 Sep 2007 11:49 GMT
>SQLException: Error during query: Unexpected Exception:
>java.io.CharConversionException message given: null
see
http://mindprod.com/jgloss/runerrormessages.html#CLASSCONVERSIONEXCEPTION

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
GArlington - 26 Sep 2007 17:08 GMT
On 26 Sep, 11:49, Roedy Green <see_webs...@mindprod.com.invalid>
wrote:
> On Mon, 24 Sep 2007 23:44:24 -0700, thushiantha...@gmail.com wrote,
> quoted or indirectly quoted someone who said :
[quoted text clipped - 6 lines]
> Roedy Green Canadian Mind Products
> The Java Glossaryhttp://mindprod.com
Something similar was discussed here to:
http://forum.java.sun.com/thread.jspa?threadID=580661&messageID=2941965
about using
<quote>
String url = "jdbc:mysql://localhost/movies";
String user = "...";
String password = "...";
Connection conn=DriverManager.getConnection(url, user, pass);
</quote>
instead of construct like
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost/
movies?"+"user=...&password=...");
To be on the safe side as well as that above I would specify the port
number too, like:
String url = "jdbc:mysql://localhost:3306/movies";
Jyrki O Saarinen - 26 Sep 2007 17:56 GMT
: Something similar was discussed here to:
: http://forum.java.sun.com/thread.jspa?threadID=580661&messageID=2941965
[quoted text clipped - 8 lines]
: Connection conn=DriverManager.getConnection("jdbc:mysql://localhost/
: movies?"+"user=...&password=...");
If you'll read the MySQL JDBC driver manual, it clearly states that all
these alternatives are equal. The original poster's problem wasn't about
connecting to the DB, but the lack of some character set conversions
which gcj doesn't seem to have.
thushianthan15@gmail.com - 27 Sep 2007 06:11 GMT
Thank you, for all your replies. I tried the same code in WinXP. It is
working well. I think gcj doesnt recognize some characters. ;(
Lew - 27 Sep 2007 14:19 GMT
> Thank you, for all your replies. I tried the same code in WinXP. It is
> working well. I think gcj doesnt recognize some characters. ;(
I keep waiting to hear good things about gcj. It hasn't happened yet.
I thought maybe it had improved since my early disappointing experiences with
it. I guess not.
And now that Java is becoming open source, and given that it's always been
free of charge, I have never seen a reason to use gcj.

Signature
Lew