好有趣的中文显示问题

bigbigbug 2001-07-24 04:34:21
当我使用jswdk时,从页面提交的中文不能正确的存储到数据库中,但数据库中的中文记录可以正确的显示到页面上;而当我使用resin时正好相反,从页面可正确的提交中文,但数据库中的中文记录却不能正确显示到页面上。这是怎么回事?是我的设置不正确?请各位大虾指教!
...全文
94 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
nicolas 2001-07-27
  • 打赏
  • 举报
回复
环境:jswdk+jdk1.3+access
1.将中文数据写入数据库
<%@ page contentType="text/html;charset=GB2312" %>
<%@ page language="java" import="java.sql.*" %>
<jsp:useBean id="databean" scope="page" class="dbbean.dbbean"/>
String strName="",strSql="";
byte[] tmpbyte=null;
strName=strName.trim();
tmpbyte=strName.getBytes("ISO8859_1");
strName=new String(tmpbyte);

strSql="insert into user_info(name) values('"+strName+"')";
databean.executeInsert(strSql);
2.将中文数据提出可以直接显示在页面上。
3.bean代码:
/*
* @dbbean.java
* Author:yjx
* Date:2001-3-21
* version:1.0v
* Function:connect database,query table,update table by parameter
*/
package dbbean;
import java.sql.*;
import java.io.*;
public class dbbean{
String sDBDriver="sun.jdbc.odbc.JdbcOdbcDriver";
Connection conn=null;
ResultSet rs=null;

/*
* constructor:try to create a dababase driver
*/
public dbbean(){
try{
Class.forName(sDBDriver);
}catch(java.lang.ClassNotFoundException e){
System.err.println("dbbean(): "+e.getMessage());
}
}

public ResultSet executeQuery(String sqlStr){
rs=null;
try{
conn=DriverManager.getConnection("jdbc:odbc:wygl");
Statement stmt=conn.createStatement();
rs=stmt.executeQuery(sqlStr);
}catch(SQLException e){
System.err.println("executeQuery(): "+e.getMessage ());
}
return rs;
}

public int executeInsert(String sqlStr){
try{
conn=DriverManager.getConnection("jdbc:odbc:wygl");
Statement stmt=conn.createStatement();
stmt.executeUpdate(sqlStr);
return 1;//成功
}catch(SQLException e){
System.err.println("executeInsert(): "+e.getMessage());
return 0;//失败
}
}

public int executeUpdate(String sqlStr){
try{
conn=DriverManager.getConnection("jdbc:odbc:wygl");
Statement stmt=conn.createStatement();
stmt.executeUpdate(sqlStr);
return 1;//成功
}catch(SQLException e){
System.err.println("executeInsert(): "+e.getMessage());
return 0;//失败
}
}

public int executeDelete(String sqlStr){
try{
conn=DriverManager.getConnection("jdbc:odbc:wygl");
Statement stmt=conn.createStatement();
stmt.executeUpdate(sqlStr);
return 1;//成功
}catch(SQLException e){
System.err.println("executeDelete(): "+e.getMessage());
return 0;//失败
}
}
}
24680 2001-07-26
  • 打赏
  • 举报
回复
建个头文件。
bigbigbug 2001-07-25
  • 打赏
  • 举报
回复
to wyzegg(蛋):show me 那个函数啦,老大。
wyzegg 2001-07-24
  • 打赏
  • 举报
回复
需要转换,我们有个函数
dragonerfish 2001-07-24
  • 打赏
  • 举报
回复
可能是字符集设的不正确!!!

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧