| Author |
MySQL problem
|
Paul Cullen
Greenhorn
Joined: Sep 07, 2007
Posts: 11
|
|
|
I have a application using a MySql database. The application retrieves information and prints it out. That bit is all working. But the problem I have when I print out the information e.g. dith m� I get dith m,.When I query the table the information comes out correct its only when the data is retrieved do I have problem..If any would could help it would be great.
|
 |
Scott Selikoff
Saloon Keeper
Joined: Oct 23, 2005
Posts: 3652
|
|
|
Try changing your output stream format from UTF8 to UTF16. It sounds like an encoding problem to me.
|
My Blog: Down Home Country Coding with Scott Selikoff
|
 |
Paul Cullen
Greenhorn
Joined: Sep 07, 2007
Posts: 11
|
|
Thanks for the reply how would i introduce utf 8 encoding. The part of the code that retrieves and outputs the data is below. [ September 22, 2007: Message edited by: Ben Souther ]
|
 |
Tarun Yadav
Ranch Hand
Joined: Sep 20, 2007
Posts: 134
|
|
I think he meant change the charset for your response output stream: http://72.5.124.55/javaee/5/docs/api/javax/servlet/ServletResponse.html#setCharacterEncoding(java.lang.String) You could also use setContentType() with the charset, as mentioned in the docs ( same link as above )
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26192
|
|
|
Moving to our servlet forum since this is about content types.
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
Rahul Bhattacharjee
Ranch Hand
Joined: Nov 29, 2005
Posts: 2300
|
|
Originally posted by Jeanne Boyarsky: Moving to our servlet forum since this is about content types.
I do not see the original poster saying anything about servlet . Nor this question is related to servlets.
|
Rahul Bhattacharjee
LinkedIn - Blog
|
 |
Deepak Bala
Bartender
Joined: Feb 24, 2006
Posts: 6588
|
|
|
Have a look at the encoding the database is currently on. Try to write with that encoding. Can you please provide some information on what technology you are using. For example Servlet -> JDBC -> DB and servlet redirects to JSP
|
SCJP 6 articles - SCJP 5/6 mock exams - SCJP Mocks - SCJP 5 Mock exam (Word document ) - SCJP 5 Mock exam in Java.Inquisition format
|
 |
Paul Cullen
Greenhorn
Joined: Sep 07, 2007
Posts: 11
|
|
I am using Eclipse.My program is a stand alone java swing front end using a MySQL database.I have set the encoding in MySQLI have queried the database with a statement from the MySQL server.This produces the correct output. But when I send it to the front end to display fron the database. It prints out "bheadh s," instead of "bheadh s�". Here is the part of the code that retrieves an d prints it out. public void verbSearch() { // connect to database books and query database try { Class.forName( JDBC_DRIVER ); // load database driver class // specify properties of JdbcRowSet JdbcRowSet rowSet = new JdbcRowSetImpl(); rowSet.setUrl( DATABASE_URL ); // set database URL rowSet.setCommand( "SELECT positive FROM verbTable4 " + "WHERE word = '" + verbList.getSelectedItem().toString()+ "'" ); // set query rowSet.execute(); // execute query // process query results ResultSetMetaData metaData = rowSet.getMetaData(); int numberOfColumns = metaData.getColumnCount(); //System.out.println( "Authors Table of Books Database:" ); // display each row while ( rowSet.next() ) { for ( int i = 1; i <= numberOfColumns; i++ ) { area.append( "\n"+ rowSet.getString( i ) + "\t"); } System.out.println(); } // end while } // end try catch ( SQLException sqlException ) { sqlException.printStackTrace(); System.exit( 1 ); } // end catch catch ( ClassNotFoundException classNotFound ) { classNotFound.printStackTrace(); System.exit( 1 ); } // end catch } // end constructor
|
 |
sudhir nim
Ranch Hand
Joined: Aug 29, 2007
Posts: 212
|
|
Try changing character encoding for eclipse workspace. Goto windows>preferences>general>workspace. change the text encoding to UTF-16 from default.
|
[Servlet tutorial] [Servlet 3.0 Cook Book]
|
 |
Paul Cullen
Greenhorn
Joined: Sep 07, 2007
Posts: 11
|
|
|
Thanks for the reply.I tried this and got my code put in japenese.
|
 |
 |
|
|
subject: MySQL problem
|
|
|