File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes MySQL problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "MySQL problem" Watch "MySQL problem" New topic

MySQL problem

Paul Cullen

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: 3753

Try changing your output stream format from UTF8 to UTF16. It sounds like an encoding problem to me.

[OCA 8 Book] [Blog]
Paul Cullen

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:

You could also use setContentType() with the charset, as mentioned in the docs ( same link as above )
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33102

Moving to our servlet forum since this is about content types.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
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

Joined: Feb 24, 2006
Posts: 6662

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 - More SCJP Mocks
Paul Cullen

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
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 ( )
for ( int i = 1; i <= numberOfColumns; i++ )

area.append( "\n"+ rowSet.getString( i ) + "\t");
} // end while
} // end try
catch ( SQLException sqlException )
System.exit( 1 );
} // end catch
catch ( ClassNotFoundException classNotFound )
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

Joined: Sep 07, 2007
Posts: 11
Thanks for the reply.I tried this and got my code put in japenese.
I agree. Here's the link:
subject: MySQL problem
It's not a secret anymore!