MySQL Forums
Forum List  »  Quality Assurance

UTF-8 database returning null
Posted by: Nisheeth Joshi
Date: January 29, 2012 12:18PM

Hello Guys

I have table which has data in utf-8 format (has data in Hindi). When I try to give a select query with where clause, I am getting a null from the query, whereas it is show the result on sql prompt. Please heplp me :( My code is as follows:::


void fname(String f)
{
try{
InputStreamReader fstream = new InputStreamReader(new FileInputStream("Hi"+f.substring(2)),"UTF-8");
BufferedReader in1 = new BufferedReader(fstream);
InputStreamReader fs1 = new InputStreamReader(new FileInputStream(f),"UTF-8");
BufferedReader in2 = new BufferedReader(fs1);
Connection con;
ResultSet rs1;
String gid,id,msg,msg2,hid;
int sid=21001;
Integer s;
Class.forName("com.mysql.jdbc.Driver");
String connectionUrl = "jdbc:mysql://localhost/corpus?" +
"user=root&password=root&characterEncoding=utf-8&useUnicode=true";
con = DriverManager.getConnection(connectionUrl);
System.out.println("Connection Established!!!");
System.out.println("Inside Try");
id=f.substring(0, 2);
System.out.println(id);
while((msg=in1.readLine())!=null)
{
msg2=in2.readLine();
System.out.println(msg);
System.out.println(msg2);
PreparedStatement ps=con.prepareStatement("Select HID from hindi where HSent = ?");
ps.setString(1,msg);
rs1 = ps.executeQuery();
// Statement stmt = con.createStatement();
// stmt.executeQuery("Select HID from hindi where HSent = '" + msg + "'");
// System.out.println(stmt.execute("Select HID from hindi where HSent = '" + msg + "'"));
// rs1 = stmt.getResultSet();
rs1.next();
hid=rs1.getString(1);
if(hid.isEmpty())
{
s = sid;
gid = id + s.toString();
sid++;
}
else
gid = id + hid.substring(2);

PreparedStatement command=con.prepareStatement("insert into english values (?,?)");
command.setString(1, gid);
command.setString(2, msg2);
}
}
catch(Exception e){System.out.println("Something went wrong!!!!");
System.out.println(e.getCause());
//e.printStackTrace();
}

}

Options: ReplyQuote


Subject
Views
Written By
Posted
UTF-8 database returning null
2779
January 29, 2012 12:18PM
1204
February 09, 2012 09:08PM
1130
February 25, 2012 01:37AM
1433
February 25, 2012 01:45AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.