Cyrillic symbols and JDBC
Posted by: Roman
Date: February 03, 2005 01:34AM

I have a problem.

I created database

create database mybase;

use mybase;

create table MYTABLE
ID bigint(10) not null,
NAME varchar(255) not null
comment = "Some table";

I using mysql-connector-java-3.1.6 и Mysql 4.1.9 on Windows 2000 Professional and Tomcat 4.1.31

I trying to run command INSERT or UPDATE with cyrillic symbol from JSP, but in table appear ??????
I trying to run command SELECT, but I get ??????? again.

Then I make insert through client mysql

INSERT INTO MYTABLE (ID, NAME) VALUES (2, 'Кириллические символы');

and I trying to get data again through JDBC and result is "2, ???????...", but through client mysql -
correct representation of symbols.

There are some piece of source

in top of JSP
<%@ page contentType="text/html;charset=windows-1251" %>

So I connect to database:

Connection conn = null;
Class.forName ("").newInstance();
String connectString = "jdbc:mysql://";
String user = "";
String password = "";
conn = DriverManager.getConnection(connectString, user, password);

So I run command INSERT

PreparedStatement pstmt = null;
String sql = "INSERT INTO MYTABLE (ID, NAME) VALUES (?, ?)";
pstmt = conn.prepareStatement(sql);
pstmt.setInt(1, 2);
pstmt.setString(2, "Кириллические символы");

in database now 2 ????????????? ???????

So I run command SELECT

PreparedStatement pstm = null;
ResultSet rset = null;
pstm = conn.prepareStatement("select ID, NAME from MYTABLE");
rset = pstm.executeQuery();
if ( {
out.print(rset.getString("ID") + " " + rset.getString("NAME"));

of course result is

2 ????????????? ???????

I tryed to connect so:
String connectString = "jdbc:mysql://";
result is 2, ???????...

and/or created database with collation and charset

DEFAULT CHARACTER SET cp1251 COLLATE cp1251_general_ci;

I got same result.

Perhaps problem is

Excuse me for my English

Options: ReplyQuote

Written By
Cyrillic symbols and JDBC
February 03, 2005 01:34AM
February 04, 2005 04:44AM

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.