<%!
//转码U_to_GB
public String U_to_GB(String s) throws UnsupportedEncodingException
{
String str=s;
str=new String(s.getBytes("GBK"),"ISO8859_1");
return str;
}public String GB_to_U(String s) throws UnsupportedEncodingException
{
String str=s;
str=new String(s.getBytes("ISO8859_1"),"GBK");
return str;
}public String send(String s){
return s;
}
%>
有时候需要转换,存入的时候转换一下,取出的时候在转换一下。我用的是tomcat一只都是这样做的
//转码U_to_GB
public String U_to_GB(String s) throws UnsupportedEncodingException
{
String str=s;
str=new String(s.getBytes("GBK"),"ISO8859_1");
return str;
}public String GB_to_U(String s) throws UnsupportedEncodingException
{
String str=s;
str=new String(s.getBytes("ISO8859_1"),"GBK");
return str;
}public String send(String s){
return s;
}
%>
有时候需要转换,存入的时候转换一下,取出的时候在转换一下。我用的是tomcat一只都是这样做的
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<%@ page language="java" %>
<html>
<body>
<%!
public String U_to_GB(String s) throws UnsupportedEncodingException
{
String str=s;
str=new String(s.getBytes("GBK"),"ISO8859_1");
return str;
}
public String GB_to_U(String s) throws UnsupportedEncodingException
{
String str=s;
str=new String(s.getBytes("ISO8859_1"),"GBK");
return str;
}
public String send(String s){
return s;
}
%>
<%Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://yeren:1433;DatabaseName=jsp";
String user="sa";
String password="sa";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String s=request.getParameter("S1");
String ss=U_to_GB(s);
String sql="insert into test(life) values('"+ss+"') ";
out.print (sql);
stmt.executeUpdate(sql);
%>
<%out.print("数据库操作成功,恭喜你");%>
<%String sql1="select * from test";
ResultSet rs=stmt.executeQuery(sql1);
while(rs.next()) {%>
<%=GB_to_U(rs.getString("life"))%>
<%}%>
<%rs.close();
stmt.close();
conn.close();
%>
</body>
</html>
这个我也用过,还有其他的方法吗,我是SqlServer2000,平台是resin,各位大哥们一定要帮帮我啊,我多送几十分啊!紧急紧急紧急紧急紧急紧急!
我试了你的代码,没有出现乱码