Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Learning Regular Expressions this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

junk characters for byte charset  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
rs1=stmt1.executeQuery("SELECT...");
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 (rs1.next())
{
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 (rs2.next())
{
System.out.println(rs2.getString(1));
}
rs2.close();
stmt2.close();
con2.close();
rs1 = stmt1.executeQuery("SELECT FIELD2 FROM FOO");
if (rs1.next())
{
System.out.println("Second try with connection1: " + rs1.getString(1));
}
rs1.close();
stmt1.close();
con1.close();
I want to know is this a JDBC techinical Spec problem or something else. nayan_khare@yahoo.com
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
nayan_khare@yahoo.com
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!