Measure the test taker's knowledge about Firebird's Chinese search using Java.

Source: Internet
Author: User

In a program I wrote in Delphi, Chinese characters like '% Chinese %' never worked. Not the Qualified Data, but all the data, which was also mentioned in firebird.net.cn, FB does not support Chinese. My colleague used. Net to implement the perfect Chinese like. Today I use Java as well as the Chinese like. It is normal and there is no problem. It may be due to a problem with the Delphi driver, either the driver itself or the sequence set to be specified when the driver opens the database, or a problem with the string format of the data that I transmit. This is not a problem with Firebird.

The test code is as follows:

Package jfb;

Import java. Io. bufferedreader;
Import java. Io. ioexception;
Import java. Io. inputstreamreader;
Import java. SQL .*;

// Import org. firebirdsql. JDBC .*;

Public class jfb
{

/**
* @ Param ARGs
*/
Public static void main (string [] ARGs) throws classnotfoundexception,
Sqlexception, ioexception
{
// Todo automatically generates method stubs
Class. forname ("org. firebirdsql. JDBC. fbdriver ");
Connection conn = drivermanager
. Getconnection (
"JDBC: firebirdsql: FIG/3050: D: // fb_test.fdb? Lc_ctype = unicode_fss ",
"Sysdba", "masterkey ");
Int select;
Bufferedreader CIN = new bufferedreader (New inputstreamreader (
System. In ));
Statement cmd = conn. createstatement ();
String Param = NULL;
Do {

System. Out. println ("0: Exit ");
System. Out. println ("1: Insert ");
System. Out. println ("2: select all ");
System. Out. println ("3: Select like ");

Param = cin. Readline ();
Select = integer. parseint (PARAM );

Switch (select ){
Case 0:
System. Out. println ("system exit ");
Break;
Case 1:
System. Out. println ("Enter the data to be inserted :");
Param = cin. Readline ();
Param = "insert into AA (bb) values ('" + Param
+ "')";
System. Out. println (PARAM );
If (cmd.exe cuteupdate (PARAM )! = 0 ){
System. Out. println ("executed successfully ");

} Else {

System. Out. println ("failed to execute ");
}
Break;
Case 2:
System. Out. println ("output all data :");
Resultset rs = cmd
. Executequery ("select * from AA ");
While (Rs. Next ()){
System. Out
. Println (RS
. Getstring ("BB "));
}

Break;
Case 3:
System. Out. println ("Enter the data to be queried :");
Param = cin. Readline ();
Param = "select * from AA where BB like '%"
+ Param. Trim () + "% '";
System. Out. println (PARAM );
Resultset RSA = cmd.exe cutequery (PARAM );
While (RSA. Next ()){
System. Out. println (RSA
. Getstring ("BB "));
}

}
System. Out. println ("======================== ");

} While (select! = 0 );

Conn. Close ();

}
}

 

Database creation statement:

Create Database 'd:/fb_test.fdb 'default Character Set utf8;

Create Table AA (BB varchar (255 ));

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.