我通过jdbc-odbc向sql server中填入中文的问题(200分)

S

sww

Unregistered / Unconfirmed
GUEST, unregistred user!
但每次看数据库只有第一个字是中文,其余全是乱码!
通过jdbc-odbc取出后一样!能不能附例程,及说明!
 
老兄,
假设你的数据库中有个table 叫user,有两个字段ID,Name.
1,query from table user.
在class 中声明 Connection con;

//init
public void init(ServletConfig config) throws ServletException {
super.init(config);
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
con = DriverManager.getConnection("jdbc:eek:dbc:test");//test为ODBC DSN
dispStmt = con.createStatement();
}//end of try
catch (Exception e) {
throw(new UnavailableException(this,"Sorry!The database did not load!/r The Info is:"+e.toString()));
} //end of catch
}//end of function init


public String getName(String aID)
throws IOException ,UnsupportedEncodingException
{
byte[] nm;
String name="",
sql;//debug use
try{
Statement dispStmt = con.createStatement();
ResultSet rs ;
synchronized(this)
{
sql = "select NAME from user where (ID = /'"+aID+"/')";
rs = dispStmt.executeQuery(sql);
}//end of synchronized
while(rs.next()){
nm = rs.getBytes("CLASSNAME");
ClassName = (new String(nm,"8859_1"));
}//end of while
dispStmt.close();
}//end of try
catch (Exception e) {
out.println("/r ERROR in getClassName:"+e.toString()+"/r");
}//end of catch
// Catolog.setQueryTimeout();
return ClassName;
}//end of function getClassName
2, save Chinese string to database
存盘时将中文string 转换成 ByteArrayInputStream;
public ByteArrayInputStream ChineseToAscii(String str)
throws UnsupportedEncodingException {
return new ByteArrayInputStream(str.getBytes("8859_1"));
}//end of function
然后,用
String userName = "中文";
...
updateStat.setAsciiStream(1,ChineseToAscii(userName),userName.length());
.....
保存.就OK啦。
以上是在Jbuilder3.0+sql7.0下通过的程序。
有问题再联系。
larry

 
唉,搞不懂,居然连jdbc-odbc桥都有中文问题,我不知道你怎么让中文显示乱码的。
这比较难。这与你的配置中的某些东西有关,太多了,以至于我不知道是哪一个。
 
接受答案了.
 
顶部