File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes junk characters for byte charset Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "junk characters for byte charset" Watch "junk characters for byte charset" New topic

junk characters for byte charset

Nayan Khare

Joined: Sep 26, 2003
Posts: 2
Hi all,
Serious Urgent problem:
i am working on a Japanese OS
i have got 2 info objects, and 2 statement objects, i am opening a connection with Properties info1:
info1.put("user", "...");
info1.put("password", "...");
Connection con1, Statement stmt1, and ResultSet rs1. After executing query with stmt1, I am opening a new connection with Properties info2:
info2.put("user", "...");
info2.put("password", "...");
info2.put("charSet", "ISO8859_1");
Connection con2, Statement stmt2, and ResultSet rs2. I am performing a close on con2,stmt2,rs2.
I am doing:
The problem is that rs1.getString(1) isn't printing the same japanese characters anymore, instead giving garbage chracters.
The sample code is:
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
Properties info = new Properties();
info.put("user", "...");
info.put("password", "....");

Connection con1 = DriverManager.getConnection("jdbc dbc:...", info);
Statement stmt1 = con1.createStatement();

ResultSet rs1 = stmt1.executeQuery("SELECT FIELD2 FROM FOO");
if (
System.out.println("First try with connection1: " + rs1.getString(1));
//Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
Properties info2 = new Properties();
info2.put("user", "...");
info2.put("password", "d...");
info2.put("charSet", "ISO8859_1");
Connection con2 = DriverManager.getConnection("jdbc dbc:HARIT", info2);

Statement stmt2 = con2.createStatement();

ResultSet rs2 = stmt2.executeQuery("SELECT FIELD2 FROM FOO WHERE FIELD1 = 2");
if (
rs1 = stmt1.executeQuery("SELECT FIELD2 FROM FOO");
if (
System.out.println("Second try with connection1: " + rs1.getString(1));
I want to know is this a JDBC techinical Spec problem or something else.
Dave Bender

Joined: Oct 16, 2003
Posts: 3
This may be wrong, but you set the charSet property to be "ISO8859_1". Shouldn't it be "ISO_8859_1" or "ISO-8859-1" with a separator between the ISO and the start of the numbers?
Nayan Khare

Joined: Sep 26, 2003
Posts: 2
I have tried with the charSet property set to "ISO_8859_1" and "ISO-8859-1" but it doesn't work, I think this is some kind of internal problem.
Thanks for the reply, hoping u would give a solution.
Nayan Khare
I agree. Here's the link:
subject: junk characters for byte charset
It's not a secret anymore!