Hi!
I have done some testing and currently the situation is like this.
If I insert the string by using a prepared statement the comparison test is successfull.
...
// Empty table
Statement statement1 = connection.createStatement();
statement1.execute("delete jahia_db_test");
// Insert string
PreparedStatement statement2 = connection.prepareStatement("insert into jahia_db_test (testfield) values (?)");
String testField = "Latin : ���� / Cyrillic : \u0419\u0416 / Chineeze : \u8bed\u8a00";
statement2.setString(1, testField);
statement2.execute();
// Fetch and compare
Statement statement3 = connection.createStatement();
ResultSet rs = statement3.executeQuery("select * from jahia_db_test");
while (rs.next())
{
String test = rs.getString(1);
if (test.equals(testField))
{
System.out.println("OK"); <------- The result
}
else
{
System.out.println("FAIL");
}
}
Statement statement1 = connection.createStatement();
statement1.execute("delete jahia_db_test");
// Insert string
PreparedStatement statement2 = connection.prepareStatement("insert into jahia_db_test (testfield) values (?)");
String testField = "Latin : ���� / Cyrillic : \u0419\u0416 / Chineeze : \u8bed\u8a00";
statement2.setString(1, testField);
statement2.execute();
// Fetch and compare
Statement statement3 = connection.createStatement();
ResultSet rs = statement3.executeQuery("select * from jahia_db_test");
while (rs.next())
{
String test = rs.getString(1);
if (test.equals(testField))
{
System.out.println("OK"); <------- The result
}
else
{
System.out.println("FAIL");
}
}
but if I concatenate strings like in the Jahia source code the comparison test FAIL:
....
// Empty table
Statement statement1 = connection.createStatement();
statement1.execute("delete jahia_db_test");
// Insert string
Statement statement2 = connection.createStatement();
String testField = "Latin : ���� / Cyrillic : \u0419\u0416 / Chineeze : \u8bed\u8a00";
statement2.execute("insert into jahia_db_test (testfield) values ('" + testField + "')");
// Fetch and compare
Statement statement3 = connection.createStatement();
ResultSet rs = statement3.executeQuery("select * from jahia_db_test");
while (rs.next())
{
String test = rs.getString(1);
if (test.equals(testField))
{
System.out.println("OK");
}
else
{
System.out.println("FAIL"); <------- The result
}
}
...
Statement statement1 = connection.createStatement();
statement1.execute("delete jahia_db_test");
// Insert string
Statement statement2 = connection.createStatement();
String testField = "Latin : ���� / Cyrillic : \u0419\u0416 / Chineeze : \u8bed\u8a00";
statement2.execute("insert into jahia_db_test (testfield) values ('" + testField + "')");
// Fetch and compare
Statement statement3 = connection.createStatement();
ResultSet rs = statement3.executeQuery("select * from jahia_db_test");
while (rs.next())
{
String test = rs.getString(1);
if (test.equals(testField))
{
System.out.println("OK");
}
else
{
System.out.println("FAIL"); <------- The result
}
}
...
The outcome is the same if I use jtds or microsofts JDBC-driver
I do always prefer prepared statements myself because I never have to think about the ' around strings. Now its hard to tell if Jahia persistence mechanisms uses prepared statements or not because its dependent of a couple of persistence frameworks.
Regards
/Lars Hagrot
