Store&read chinese characters in MS SQL server 2000 using Java

Hi,
I have a problem to store Chinese characters in MS SQL Server 2000, storing question marks(??????) instead of Chinese characters
I am using JSF framework, SUN APPLICATION Server 9.1 , MS SQL Server 2000 server and Microsoft data source driver class (com.microsoft.sqlserver.jdbc.SQLServerDataSource) to connect db.
I have one solution:
IN JSP:
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
and
In database column type should “nvarchar” in place of varchar
while inserting or updating the same need to add ‘N’ prefix with the value like insert into client(Name, Id ….) values (N+)
the above is working fine but the problem is here i have already defined database with 100s of tables I cant change database tables as well as queries
Thanks,
Sathi

I don't know any betterer option, than to copy the database tabels redefining the Chinese data fields as nvarchar.
To be frank I had also problems writing to a html file Chinese text stored in MS SQLServer 2000 nvarchar fields.
The following worked:'
     public String getEncodedData(ResultSet resultSet, int columnIndex, String charset)
     throws SQLException
          //final String methodName = "getEncodedData";
          InputStream binaryStream =resultSet.getBinaryStream(columnIndex);
          String readStringFromStream=readStringFromStream(binaryStream, charset);//UTF_16LE);
          return readStringFromStream;
     public String readStringFromStream(InputStream inputStream, String charset) {
          final String methodName = "readStringFromStream";
          StringBuffer buffer = new StringBuffer();
          try {
               int ch;
               InputStreamReader isr = new InputStreamReader(inputStream, charset);
               Reader in = new BufferedReader(isr);
               while ((ch = in.read()) > -1) {
                    buffer.append((char)ch);
               in.close();
               return buffer.toString();
          } catch (IOException exception) {
               Log.printError(this,methodName, exception);
               return null;
     }And writing it to file:
     public void writeEncodedStringToFile(String text, String filePath, String charset, boolean append){
          final String methodName = "writeEncodedStringToFile";
          OutputStreamWriter writer= null;
          try {
               FileOutputStream fileOutputStream = new FileOutputStream(filePath, append);
               writer = new OutputStreamWriter(fileOutputStream, charset);
               writer.write(text);
          } catch (IOException exception) {
               Log.printError(this,methodName, exception);
          }finally{
               try {
                    writer.close();
               } catch (IOException exception) {
                    Log.printError(this,methodName, exception);
     }Edited by: astlanda on Feb 10, 2009 11:13 PM
Edited by: astlanda on Feb 10, 2009 11:21 PM

Similar Messages

  • How to insert chinese data into MS SQL Server 2000 through JDBC

    I am trying to insert chinese data into MS SQL server 2000 using JDBC. how to do this?
    can anybody help me.
    thanx.

    I am trying to insert chinese data into MS SQL server 2000 using JDBC. how to do this?
    can anybody help me.
    thanx.

  • SQL server 2000 with Java Problems

    Dear Sir.
    I am a new user for SQL server 2000 with java. Nevertheless, I developed an application for store images and text data into SQL 2000 database using java. Presently my system is running 12-client computer with one server computer, I installed SQL server 2000 into server then I access (save, insert, select, and get report) through ODBC diver to server using java application, system is ok but some time the server computer is getting struck.
    Please let me know if there is a solution to overcome this problem.
    My client computer configuration
    Windows xp
    1.8 MHz CPU � 512 � 768 RAM
    My Server computer configuration
    3.0 Dual core Intel - 1 GB RAM
    Window 2000 server

    but some time the server computer is getting struck.Can you measure which application is eating up the resources? Anyway, the hardware sounds OK for that number of clients, but of course it depends on the intensity they work with.
    The suspicious part is the ODBC driver. Is there a reason not to use the JDBC driver for SQL server provided by microsoft? I guess it will speed things up.
    Mike

  • How to connect Sql Server 2000 using JDBC ODBC Driver

    How to connect Sql Server 2000 using JDBC ODBC Driver ?
    plz Send Syntax.
    thanks

    In SQL Server 2000 the driver class is com.microsoft.jdbc.sqlserver.SQLServerDriver
    The connection URL for the default SQL Server 2000 database is jdbc:sqlserver://localhost:1433
    Class.forName(
      "com.microsoft.sqlserver.jdbc.
      SQLServerDriver");
    String url =
      "jdbc:sqlserver://localhost:1433";
    Connection conn = DriverManager.
      getConnection(
      url, "sa", "sqlserver");

  • Migrating Japanese Characters from MS SQL Server 2000 to Oracle 9i usng Jsp

    Hi ,
    I have a situation where the Japanese characters are to be migrated from MS SQL Server 2000 to Oracle 91 and then render the same using JSP.
    I followed the below approach,
    1. Extract the Japanese data from MS SQL Server and generate an XML
    2. Parse the XML and store it into Oracle 9i database which is of UTF-8 encoding.
    3. On retreiving and rendering using the Shift-JIS adds few junk characters additionally.
    When I try to copy paste the Japanese contents from XML to a text file, it is working fine.
    Could some one help me in resolving this issue?
    It is very urgent, and any help would be greatly appreciated.

    There is documentation in the reference guide sent with the workbench, there is this discussion forum, the support web page (which includes tech notes and FAQ's), and the company specific procedural language documentation.
    There is also an older document for use with the old sybase toolkits which may be obscelete, and there are some internal documents which were for internal consumption.
    Turloch
    Oracle Migration Workbench Team

  • Error while connecting to SQL Server 2000 using Heteregenous Services 11g

    Hope this is the right thread to post on! We have been given the challenge of connecting to and reading data from a SQL Server 2000 database.
    Our Infrastructure guys have set up the network access.
    The SQL Server DB is set to windows NT Authentication only (N.B. NOT Mixed Mode) as there is an application running against the DB locally that will not run under Mixed Mode.
    Our Oracle partner has download and installed the 11g Heteregenous Services. all works fine until the point we try to create the DBLink and then connect to the SQL Server DB when we get:
    SQL> CREATE DATABASE LINK infoteam1.sco.infoteam.co.uk CONNECT TO "sco.infoteam.co.uk/infoteam" IDENTIFIED BY "########" USING 'dg4msql';
    Database link created.
    SQL> select * from "systables"@infoteam1.sco.infoteam.co.uk;
    select * from "systables"@infoteam1.sco.infoteam.co.uk
    ERROR at line 1:
    ORA-28500: connection from ORACLE to a non-Oracle system returned this message:
    [Oracle][ODBC SQL Server Driver][SQL Server]Login failed for user
    'sco.infoteam.co.uk/infoteam'. Reason: Not associated with a trusted SQL Server
    connection.[Oracle][ODBC SQL Server Driver]Invalid connection string attribute
    ORA-02063: preceding 2 lines from INFOTEAM1.SCO.INFOTEAM.CO.UK
    The question is can we (and if so how)?) connect to the SQL Server using an NT Windows Authorised account?
    Jeremy

    Hi,
    Please look at MOS note
    ORA-28500: Generic connectivity using ODBC DSN over mapped drive fails [ID 105210.1]
    Ora-28500 with Ms Sqlserver - Not associated with a trusted SQL Server connection [ID 333775.1]
    Regards,
    Edited by: gjilevski1 on Aug 31, 2010 8:23 AM

  • Portal 4.0 with MS SQL Server 2000 using CLOBs

    Hello,
    I'm driving Portal 4.0 with MS SQL Server 2000. I have encountered serious
    problems when trying to persist events (e.g. RuleEvent) to database. In my
    application-config.xml file I have JdbcHelper attributes
    ShouldUseClobsForReads & -Writes set to 'false' as they should be or
    mssqlserver4v70 driver.
    It seems that when it is time to write the event to database, Portal4.0
    can't find JdbcHelper MBean configuration values and therefore it uses
    default values (=true) for both attributes.
    Otherwise reading and writing works fine with MS SQL Server 2000 (at least
    DATA_SYNC_ITEMs).
    Any help appreciated.
    Regards,
    JR
    P.S.
    Here are some excerpts from the console output:
    [BufferManager$PersistenceRequest.execute():247]
    PersistenceRequest::execute -> write to database
    [AbstractDatabasePersister.persist():135] Persister::persist -> write the
    events. size=2
    *** com.bea.p13n.util.jdbc.JdbcHelper.getInstance() @ JdbcHelper.java:122
    [JdbcHelper.getInstance():139] No instance found for
    sun.misc.Launcher$AppClassLoader@71732b
    [JdbcHelper.<init>():111] Unable to find JdbcHelper Configuration ...using
    defaults: java.lang.IllegalStateException: Not in application context
    at
    com.bea.p13n.management.ApplicationHelper.getApplicationName(ApplicationHelp
    er.java:119)
    at
    com.bea.p13n.management.ApplicationHelper.getApplicationConfigurationMBean(A
    pplicationHelper.java:440)
    at
    com.bea.p13n.management.ApplicationHelper.getServiceConfigurationMBean(Appli
    cationHelper.java:318)
    at com.bea.p13n.util.jdbc.JdbcHelper.<init>(JdbcHelper.java:102)
    at
    com.bea.p13n.util.jdbc.JdbcHelper.getInstance(JdbcHelper.java:141)
    at
    com.bea.p13n.util.jdbc.JdbcHelper.getConnection(JdbcHelper.java:265)
    at
    com.bea.p13n.tracking.internal.persistence.AbstractDatabasePersister.getConn
    ection(AbstractDatabasePersister.java:202)
    at
    com.bea.p13n.tracking.internal.persistence.AbstractDatabasePersister.persist
    (AbstractDatabasePersister.java:140)
    at
    com.bea.p13n.tracking.internal.persistence.BufferManager$PersistenceRequest.
    execute(BufferManager.java:250)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
    *** com.bea.p13n.util.jdbc.JdbcHelper.getInstance() @ JdbcHelper.java:122
    [JdbcHelper.getInstance():131] Got instance for
    sun.misc.Launcher$AppClassLoader@71732b
    [JdbcHelper._setClob():412] ######## JdbcHelper: String length = 496
    [JdbcHelper._setClob():420] ######## JdbcHelper: setting CLOB String with
    setCharacterStream()
    <7.1.2002 14:27:41 GMT+02:00> <Error> <Tracking> <Error persisting event to
    database. java.sql.SQLException: java.sql.SQLException: This JDBC 2.0 method
    is not implemented
    at
    weblogic.jdbc.rmi.SerialPreparedStatement.setCharacterStream(SerialPreparedS
    tatement.java:428)
    at com.bea.p13n.util.jdbc.JdbcHelper._setClob(JdbcHelper.java:424)
    at com.bea.p13n.util.jdbc.JdbcHelper.setClob(JdbcHelper.java:404)
    at
    com.bea.p13n.tracking.internal.persistence.BehaviorTrackingPersister.setPrep
    aredStatementData(BehaviorTrackingPersister.java:93)
    at
    com.bea.p13n.tracking.internal.persistence.AbstractDatabasePersister.persist
    (AbstractDatabasePersister.java:157)
    at
    com.bea.p13n.tracking.internal.persistence.BufferManager$PersistenceRequest.
    execute(BufferManager.java:250)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)

    Hi,
    I would suggest better to have a backup of existing database remove your existing SQL server. Install the  one given by SAP. And restore your previous databases.
    --Ragu

  • SQL Server 2000 - JDBC + Java Applet problem

    Hai
    I have some problem connecting my SQL server database with Java.
    I use Applet to make my interface.
    I use Windows 2000 server.
    Here is my program listing :
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    import java.sql.*;
    public class VLookup extends JApplet {
    String database = "jdbc:odbc:Driver={SQL Server};SERVER=Windows2000;uid=sa;pwd=;Database=User-Phone Database";
    String user = "sa";
    String password = "";
    Statement s;
    Connection c;
    JTextField searchFor = new JTextField(10);
    JLabel completion = new JLabel(" ");
    JTextArea results = new JTextArea(40, 20);
    public void init() {
    searchFor.getDocument().addDocumentListener(new SearchL());
    JPanel p = new JPanel();
    p.add(new Label("ID to search for :"));
    p.add(searchFor);
    p.add(completion);
    Container cp = getContentPane();
    cp.setLayout(new BorderLayout());
    cp.add(p, BorderLayout.NORTH);
    cp.add(results, BorderLayout.CENTER);
    try {
    Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
    c = DriverManager.getConnection(database, user, password);
    s = c.createStatement();
    } catch(Exception e) {
    results.setText(e.getMessage());
    class SearchL implements DocumentListener {
    public void changedUpdate(DocumentEvent e){}
    public void insertUpdate(DocumentEvent e){
    textValueChanged();
    public void removeUpdate(DocumentEvent e){
    textValueChanged();
    public void textValueChanged() {
    ResultSet r;
    if(searchFor.getText().length() == 0) {
    completion.setText("");
    results.setText("");
    return;
    try {
    r = s.executeQuery("SELECT " + "Tipe " + "FROM " + "Time " + "WHERE " + "(Tipe Like '" + searchFor.getText() + "%') "
    + "GROUP BY " + "Tipe " + "ORDER BY " + "Tipe " );
    if(r.next())
    completion.setText(r.getString("Tipe"));
    r = s.executeQuery("SELECT " + "ID_Pengguna, Phone_Number, Tipe " + "FROM " + "Time "
    + "WHERE " + "(Tipe ='" + completion.getText() + "') "
    + "GROUP BY " + "ID_Pengguna, Phone_Number, Tipe "
    + "ORDER BY " + "ID_Pengguna, Phone_Number " );
    } catch(Exception e) {
    results.setText(searchFor.getText() + "\n");
    results.append(e.getMessage());
    return;
    results.setText("");
    try {
    while(r.next()) {
    results.append(r.getString("ID_Pengguna") + ", " + r.getString("Phone_Number") + ", " + r.getString("Tipe") + "\n");
    } catch(Exception e) {
    results.setText(e.getMessage());
    public static void main(String[] args) {
    JApplet applet = new VLookup();
    JFrame frame = new JFrame("User ID");
    frame.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e){
    System.exit(0);
    frame.add(applet);
    frame.setSize(500, 200);
    applet.init();
    applet.start();
    frame.setVisible(true);
    } ///:~
    And java catch error like this : access denied (java.lang.RuntimePermission access ClassInPackage.sun.jdbc.odbc)
    What is wrong ??
    Is there any problem with my DNS ? 'cos I don't know how to set up my DNS.
    Can u help my with this problem ??
    Thank's

    You need to read up on what applets are capable of. Applets generally cannot open connections to things like databases due to sandboxing. There are a couple of ways to get around this. The applet can connect to a servlet on the same machine from which it came and have the servlet do the database accesses. Alternately, you can create a signed applet which allows you to get around some of these sandboxing issues.If tried to make localhost on my computer ( by setting my IIS configuration setting, and using Configure SQL XML Support in IIS I've created a new http://localhost/skripsi to my SQL database.
    Is there any command that I have to add to my program listing so the applet can work as I wish ??
    Is there any way to use applet to connect my database withaout using servlet, and can u explain siggned applet to mey ??
    Sorry, I don't really know java very well.
    driver type 4 ??

  • Connect SQL Server 2000 using JDBC

    Hi all,
    We have installed the microsoft sql server 2000 into 3 different pcs which is not the server. we have installed the jdbc driver into the server and wish to connect the database from the 3 pcs using that jdbc driver from the server. may i know is it possible to connect the database and if it is possible, the database url is it something like      jdbc:sqlserver://<host_name>:<port>;DatabaseName=<db_name>?
    Also may i know what is actually the host name? like is it the host name of j2ee engine or the ip address where the database resides in. also for the port is it 1433 for microsoft sql server 2000 and if it is fix meaning that only 1433 is the port for sql server 2000?
    Thanks

    Hi,
    see <a href="https://www.sdn.sap.com/irj/sdn/thread?threadID=48126">this Thread</a>
    HTH,
    Carsten
    The hostname is the name (or IP-Adress) of your PCs. The Port of SQL Server may vary, but by default it is 1433.

  • Is it possible to remove Locks in SQL server 200 using java code...???

    Hi floks,
    I had i trickey situation in which my application is creating the locks over the tables in the
    DB(SQL server 2000) . Iam using Struts frame work 1.1 + jsp in our application.
    Iam bit worried wether the locks can be removed with the java code which suits the Struts
    framework...
    Please help me with proper code snippet to over come the situation.
    Thanks in anticipation
    Shiv

    iam looking to make a query in such a way that it can be triggered with
    java code whish removes all the locks
    is it possible...?
    i tried the nolock situation even i cant get the situations
    and the query where it is getting locked as our application is big enough with
    numerous number of queries

  • SQL server 2000 and java

    Hi all,
    i am about to developpe a java application that has to do the following tasks:
    1. detect all SQL server existing databases .
    2. for every database (SQL server database) be able to connect to the chosen database and detect all the tables Regarding every SQL server database.
    for the first point ,i thought about searching my hole system for the files of SQL server databases with the criteria of its extension (.SQL serverEXtension database file). But i don't know if this method is efficient and if there are not other methods for this purpose ?!
    for the second point i'm wondering if there exist methods or Classes that return the Set of all the tables within a given SQL server database ; and also return the Set of the Fields (Attributes )within this given database.
    It remains one important point: how to connect to a SQL Server database from a java Program.
    I'm waiting for your hints and ideas... Thanks indeed.

    Try DatabaseMetaData for databases, tables and fields. There's even more information you can get from it, check the API documentation.
    Alin.

  • Can not read Chinese data when DB Connect to SQL server 2000

    Hi,
       Our BW server( BW3.5 not unicode ) is installed on MS SQL server 2000. We try to connect the BW SQL server with db connect function. We create some test views in the Northwind DB. We are be able to access data from source system in rsa1 by db connect. The problem is that all the Chinese characters are displayed as ?????. Is there any special setting for accessing multibyte characters in MS SQL server 2000? Please advise.
    Thank you,
    Jeff

    The field of VIEW in the sqlserver which code is chinese must be the nvarchar.
    You can try it.

  • Using Unicode with MS-SQL-Server 2000

    Hello,
    i want to migrate my coldfusion application to support
    unicode. for that i read some articles here in the knowledge bas e
    and on the web. So i actually tested with:
    * correct use of cfcontent,cfprocessingdirective
    * storing source-files with UTF8 (BOM)
    * activating Unicode-handling for strings in
    datasource-settings of coldfusion admin
    * using nvarchar instead of varchar on mssql-server
    my firsts test displaying diffrent characters of different
    languages (chinese, japanese, arabic) look good. Tests storing and
    selecting example strings in that languages also look good.
    but now i read, that mssql stores unicode data with the UCS-2
    implementation and cannot handle UTF-8 directly. but my
    coldfusion-application will be converted to UTF-8.
    now my question: Do i have to do special handling storing and
    selecting the application data or does this the mssql jdbc driver
    for me. What about characters in some languages which use 3 Bytes
    in UTF8. How are they handled when MS-SQL-Server 2000 uses UCS-2
    (max 2 Bytes) instead?
    Many regards for your answers
    McD

    mcd wrote:
    > now my question: Do i have to do special handling
    storing and selecting the
    > application data or does this the mssql jdbc driver for
    me. What about
    > characters in some languages which use 3 Bytes in UTF8.
    How are they handled
    > when MS-SQL-Server 2000 uses UCS-2 (max 2 Bytes)
    instead?
    no need to worry, the db driver will handle that for you.
    just make sure your
    encoding is the same end-to-end.
    also a potential gotcha has just been exposed in unicode
    handling for sql server
    related to cfqueryparam under loads, you need to convert
    everything to "N"
    datatypes to avoid this. see jochem's blog:
    http://jochem.vandieten.net/2008/03/22/ms-sql-server-and-the-coldfusion-string-format-sett ing/

  • Storing Unicode data in SQL Server 2000

    hello,
    I'm currently developing a website which must store Cyrillic characters in a SQL Server 2000 database. I know the database can store the data correctly because when I use the MS Front end to connect to the database I am able to copy/paste the text into the database columns correctly.
    Retrieving the data from the database also works correctly and is displayed with the correct characters.
    The problems I am having is that the text seems to get garbled during the SQL insert by the database driver. If I print out the SQL just before it is inserted the characters are still correct but once they get into the database they are wrong. I'm using the JDBC drive to connect to the database.
    Any help would be appreciated,
    Alan

    I change the way I was storing the data from using unicode to getting the char values of each letter (ie \u1041 for &#1041;) and storing them in the database. Then I parse the numbers when I bring them back out and combine them into the original String

  • Trouble with MS SQL Server 2000 vs. Java

    Hi, how do i store binary files in database MS SQL Server 2000 ?
    How do I attach it to some information stored in the database?
    Can I do some sql statement in my java application to do this or do I have to use some MS SQL Server 2000 tools ?

    i wanted to store a binary object such as image fromk java file into ms sql 2000 server and retreive it using the preparedStatement how to accomplish the task
    please give me a hint with proper and simple example.
    thanking you...........

Maybe you are looking for

  • Buying Apple Watch in US later in the year for Australian use

    Later in the year I am thinking about purchasing an Apple Watch in the US while on my holiday over there. I am wondering, if I bought an Apple Watch there.. Will it work/pair with my Australian phone.

  • How to activate ACROBAT X PRO?

    HELP!!!!  I have the teacher/student edition for acrobat X pro.  I originally downloaded to my desktop.  However, I now have a laptop w/o drive.  I downloaded the 30 day trial which has expired.  I have the product/activation code from my orig. softw

  • IPhone always shows 3G when waking from sleep

    Lately it seems that whenever I wake the phone from sleep, the screen shows 3G at the top, then switches to the wifi symbol after a couple of seconds. My phone is always on wifi at home, at my parents', and at my in-laws, so why does it always show t

  • [iphone] sub ViewController in UITableView and Interface Builder

    Hello, I created a UITableView-based application and now I would like to display a simple view after selecting a cell (drilldown feature). I create a xib file in Interface Builder by following the guide "Configuring the Views for Additional Navigatio

  • Baseline Compliance Check Loopback0

    I'm working on a Baseline Template for compliance.  One of the interfaces that we use across all our routers is Loopback 1.  I want to use a baseline template to check if Loopback 0 exists and then if it exists, I want to check certain lines in its i