Subject | Character set problem in using prepared statement |
---|---|
Author | venushau |
Post date | 2006-08-24T08:11:39Z |
I'm using Jaybird-2.2.0snapshot_20060810JDK_1.4 with Firebird
embedded server (Firebird-2.0.0.12724-0_embed_win32) for testing.
It happens to me that using UNICODE_FSS as the character set and
insert a record using prepared statement gives the problem as it
interpretes a character as an unicode character which stores at a
length of three.
Here is a test program that returns an inconsistence result by using
prepared statements:
---------------------------------------------------------
package test.data;
import java.sql.*;
public class TestData
{
public static void main(String[] args) throws
ClassNotFoundException, SQLException
{
Connection conn = test.firebird.TestFBConnection.getConnection
("C:\\employee.fdb");
PreparedStatement ps = null;
try
{
ps = conn.prepareStatement("DROP TABLE employee");
ps.executeUpdate();
ps.close();
ps = null;
}
catch(Exception e)
{}
ps = conn.prepareStatement(
"CREATE TABLE employee (" +
" name varchar(30)," +
" gender char(1)" +
")");
ps.executeUpdate();
ps.close();
ps = null;
conn.commit();
ps = conn.prepareStatement("INSERT INTO employee (name,
gender) VALUES ('peter', 'M')");
ps.executeUpdate();
ps.close();
ps = null;
ps = conn.prepareStatement("INSERT INTO employee (name,
gender) VALUES ('john', ?)");
ps.setString(1, "M");
ps.executeUpdate();
ps.close();
ps = null;
conn.commit();
ps = conn.prepareStatement("SELECT * FROM employee WHERE
gender = 'M'");
ResultSet rs = ps.executeQuery();
while (rs.next())
{
System.out.println(rs.getString("name") + ", '" +
rs.getString("gender") + "'");
}
rs.close();
ps.close();
rs = null;
ps = null;
}
}
---------------------------------------------------------
The result only returns a single record:
peter, 'M '
Probably it didn't happen in earlier Jaybird 2.0.0 versions since
I've been using it for a rather long time in doing the same thing.
Hope this help.
embedded server (Firebird-2.0.0.12724-0_embed_win32) for testing.
It happens to me that using UNICODE_FSS as the character set and
insert a record using prepared statement gives the problem as it
interpretes a character as an unicode character which stores at a
length of three.
Here is a test program that returns an inconsistence result by using
prepared statements:
---------------------------------------------------------
package test.data;
import java.sql.*;
public class TestData
{
public static void main(String[] args) throws
ClassNotFoundException, SQLException
{
Connection conn = test.firebird.TestFBConnection.getConnection
("C:\\employee.fdb");
PreparedStatement ps = null;
try
{
ps = conn.prepareStatement("DROP TABLE employee");
ps.executeUpdate();
ps.close();
ps = null;
}
catch(Exception e)
{}
ps = conn.prepareStatement(
"CREATE TABLE employee (" +
" name varchar(30)," +
" gender char(1)" +
")");
ps.executeUpdate();
ps.close();
ps = null;
conn.commit();
ps = conn.prepareStatement("INSERT INTO employee (name,
gender) VALUES ('peter', 'M')");
ps.executeUpdate();
ps.close();
ps = null;
ps = conn.prepareStatement("INSERT INTO employee (name,
gender) VALUES ('john', ?)");
ps.setString(1, "M");
ps.executeUpdate();
ps.close();
ps = null;
conn.commit();
ps = conn.prepareStatement("SELECT * FROM employee WHERE
gender = 'M'");
ResultSet rs = ps.executeQuery();
while (rs.next())
{
System.out.println(rs.getString("name") + ", '" +
rs.getString("gender") + "'");
}
rs.close();
ps.close();
rs = null;
ps = null;
}
}
---------------------------------------------------------
The result only returns a single record:
peter, 'M '
Probably it didn't happen in earlier Jaybird 2.0.0 versions since
I've been using it for a rather long time in doing the same thing.
Hope this help.