最好返回vector,collection没有串行化
解决方案 »
- ~~~高分求助,关于淘宝购物付款时支付宝的密码加密问题!
- 邮箱服务器获取账户
- spring有哪些好处和坏处
- 请问哪里有好的不错的HQL的学习资源啊?还有哪里有相关的HQL查询练习来练手?
- 求一正则表达式
- JBuilder2005中配置struts自带连接池的问题
- 有人能告诉我以下代码的具体工作流程吗?
- 可否对某一个class的不同方法做不同的客户端权限分配
- Deployment tool问题
- strut2 用户登录跳转到首页 如何自动从数据库中读取公告显示在首页?
- !!!!!精通CMP的兄弟进来看看了,这个问题我研究了三天了还没有解决啊!!帮帮忙了!!!!!!!!!
- tomcat为什么要和apache一起使用啊,好象光有tomcat就够了啊
还有一个可能是你是从别的数据库导入数据到Oracle的,
如果是这样的话,注意把表名和字段名改成大写的
1、如果说是中文专码的问题,我改成了下面的语句了:select object (p) from OrYg as p where p.jh like '%?1%'然后,用:Collection c=client.findJH("245")
还是不行。
2、关于字段名和表名是用JBuilder自动连接引入的,不需要手工输入,改成了大写则出错了。
看来真是中文的问题了。我用String 对比就是不行。改用其他的数值型Field查照就可以了:findKxd:
select Object (p) from OrYg as p where p.kxd > ?1客户端:
Collection c=client.findbyKxd((float)41);
System.out.print("c.size= "+c.size()+"\n");
Iterator i=c.iterator();
while(i.hasNext())
{
OrYgRemote oryg=(OrYgRemote)i.next();
try
{
System.out.print("井号: "+oryg.getJh()+"\n");
}
catch(Exception e) {
e.printStackTrace();
} }显示正确了:
-- Initializing bean access.-- Succeeded initializing bean access through Home interface.-- Execution time: 4890 ms.-- Calling findbyKxd(41.0)-- Succeeded: findbyKxd(41.0)-- Execution time: 1391 ms.-- Return value from findbyKxd(41.0): [weblogic.rmi.cluster.ClusterActivatableRemoteRef@2784134a - host ...c.size= 36
井号: ??92-5
井号: ??92-5
井号: ??55-4
井号: ??55-4
井号: ????7-44-?ì245
井号: ????7-44-?ì245
井号: ????7-44-?ì245
井号: ????7-44-?ì245
井号: ????7-44-?ì245
井号: ????7-44-?ì245
井号: ?¤??2-3-?ì1503
井号: ??6-J24
井号: ??13-202
井号: ??13-202
井号: ??13-202
井号: ??13-202
井号: ??13-202
井号: ??13-202
井号: ??13-202
井号: ??13-202
井号: ??13-202
井号: ??13-202
井号: ??13-202
井号: ??13-202
井号: ??24-?ì533
井号: ??2-?±207
井号: ????8-26-?ì9
井号: ??2-?±501
井号: ??56-11-13
井号: ??56-11-13
井号: ??56-8-?±10
井号: ??56-8-?±10
井号: ??56-8-?±10
井号: ??2-?±501
井号: 7-45-?ì266
井号: ??13-404 现在问题是,我难道不能用String来查询么?不能用Field为字符串的来搜索?这里中文转换如何处理?再一次感谢Njuabc()!!!!
中文问题解决,关键是,查询的时候,怎么办?
唉!
这里以Oracle9I为例来说明jdbc中的中文问题.首先查询数据库:
select * from v where parameter='NLS_CHARACTERSET';
得到数据库的字符集,如果ZHS16GBK,则JDBC的操作不需要转码;如果是us7ascii,则需要转码或者作相关配置.下面以使用不同的数据库驱动程序为例来介绍.
1. 使用Thin Driver
如果使用Thin Driver,那么需要在查询数据库的时候将字符集由ISO转换为GBK,写入数据库的时候将字符集由GBK转换为ISO.
举个例子:
插入一条记录:
Connection conn=null;
PreparedStatement pstmt = null;
try {
String strSql="insert into tabA(A,B) values('1111','王超')";
conn=ds.getConnection();
strSql = new String(strSql.getBytes("GBK"), "ISO-8859-1");
pstmt = conn.prepareStatement(strSql);
pstmt.executeUpdate();
}
catch (Exception e) {
//logger.error(e, e);
}
finally {
disconn(conn, pstmt);
}
查询一条记录:
Connection conn=null;
PreparedStatement pstmt = null;
ResultSet rs=null;
try {
String strSql="select B from tabA where A='1111'";
conn=ds.getConnection();
strSql = new String(strSql.getBytes("GBK"), "ISO-8859-1");
pstmt = conn.prepareStatement(strSql);
rs=pstmt.executeQuery();
String strB;
if (rs.next()){
strB=new String(rs.getString(1) .getBytes("ISO-8859-1"), "GBK");
}
catch (Exception e) {
//logger.error(e, e);
}
finally {
disconn(conn, pstmt, rs);
}
这里建议你在属性文件里设置oracle字符集,根据字符集判断
是否转码,以增加应用的移植性.
将中文参数进行转码URLEncoder.encoder
然后在b.jsp中转换回来
public String getStr(String inputStr) {
try{
if (inputStr == null) inputStr = "";
String temp_p=inputStr;
byte[] temp_t=temp_p.getBytes("ISO8859-1");
String temp=new String(temp_t);
temp=convertSql(temp);
return temp;
}
catch (Exception e){
}
return null;
}
1、
<%@ page contentType="text/html;charset=gb2312" %>
<%
String a="中文";
out.println(a);
%>
通过调试,在我的jb下是可以的。
2、
String a="中文";
String temp=new String(a.getBytes("ISO-8859-1"),"gb2312");
out.println(temp);
肯定是不行的。
3、
String temp=new String(a.getBytes("ISO-8859-1"),"gb2312");
一般对于得到提交后的中文数据进行转换,因为中文经过提交时变成了内码。
package db;import java.util.*;
import java.sql.*;
import java.io.*;public class DbConnection{
// 这里是连接数据库等方法
....
// to gb2312
public static String bytes2gb(String gb) {
String s =null;
if(gb!=null) {
try{
s = new String(gb.getBytes("ISO8859_1"),"GB2312");
}catch(Exception e) {
System.out.println(e.toString());
e.printStackTrace();
}
}
return s;
}
// to bytes
public static String gb2bytes(String bytes) {
String s =null;
if(bytes!=null) {
try {
s = new String(bytes.getBytes("GB2312"),"ISO8859_1");
}catch(Exception e){
System.out.println(e.toString());
e.printStackTrace();
}
}
return s;
}
}使用方法:凡是用到rs.getString()语句的改成:(从数据库读出文件)
db.DbConnection.bytes2gb(rs.getString("title"));凡是request.getParameter()改成:(即将写入数据库的数据)
db.DbConnection.gb2bytes(request.getParameter("sign"));
用这个方法时,你的JDBC在EJB的那个XML中的设置时,必须用诸如这样的语句(我用的是MYSQL)
jdbc:mysql://localhost/addressbook?user=root&password=jjx&useUnicode=true&characterEncoding=gb2312"
主要是password后面的那一句,而且还有一点,就是你的数据库的字符集必须设置成unicode,MYSQL默认是iso8859-1,因此就这样,ORACLE安装时可以选字符集的,一般默认是你操作系统的字符集,一定要选成alu32这个选项,要不然,HOHOHOHOHOHO
select Object (p) from OrYg as p where p.yybh = ?1
或者
select Object (p) from OrYg as p where p.yybh like '%?1%'根据你的回答,我想在调用的时候,传入数据:
String yybh="9";
Collection c=null;
try
{
c=client.findYybh(new String(yybh.getBytes("gbk"),"ISO-8859-1"));//client.findbyKxd((float)41);
}
catch(Exception e) {
e.printStackTrace();
} System.out.print("c.size= "+c.size()+"\n");但是结果还是空的.在CMP里面怎么在查询的时候转换中文?麻烦您再提示一下.
例如: <%= request.getParameter("showword")%> 2 与数据库有关的各种sql操作 这里使用的Access没有发生问题。
3 读取HTML form表单中递交的中文值 在jswdk中需要加以编码,较为简洁的写法如:
String name1=new
String(request.getParameter("user_id").getBytes("ISO8859_1")); 另外,在jdk1.3的支持下,不需要加入 <%@
page contentType="text/html;charset=gb2312"
%> 而在jdk1.2.2下面,即使2种方法同时运用也很不稳定。 而在resin平台,情况较好。只要在页面第一行加入: <%@
page contentType="text/html;charset=gb2312"
%> 即可正确处理中文。 如果再加编码则反而不对。 5 session中包含的中文 在jswdk中,奇怪的是如果从form中读出的值经过编码则可正确显示;
但直接赋予中文值则不行。
resin平台很好,同上。 6 对于对变量赋中文值后正确显示中文。 例如以下程序: <%@ page contentType="text/html;charset=gb2312"
%>
<html><head></head><body>
<%
String
Hi="你好";
byte[] tmpbyte=Hi.getBytes("ISO8859_1");
Hi=new
String(tmpbyte);
out.print(Hi);
%>
</body></html> 同样是jswdk1.0.1,以上的表示方法在jdk1.2.2中没有问题,但在jdk1.3下却无法显示。 resin平台很好,同上,经过测试,只需要在<head>中补上 <meta
http-equiv="Content-Type" content="text/html;
charset=gb2312">
而不需要<%@ page
contentType="text/html;charset=gb2312" %>也能正确显示中文。 体会: jswdk也许只能用于普通开发,稳定性和其它问题可能不如商业软件。
由于jdk1.3版性能要好于jdk1.2.2很多倍,并且对中文的支持也较好,所以应该加以采用。 作为免费的商业软件,resin不仅速度快,稳定,自动编译,可指出出错行,可在服务器端支持使用javascript等,而且,至少我觉得对中文的支持很好。 当然,如果不必做任何处理即可正确显示中文将是我们所期待的。 另外,相信在unix/linux/solaris下应该没有这样的问题。我讲的已经够清楚了吧
public static String toChinese(String strvalue)
{
try{
if(strvalue==null)
return null;
else
{
strvalue = new String(strvalue.getBytes("ISO8859_1"), "GBK");
return strvalue;
}
}catch(Exception e){
return null;
}
}
VALUE进数据库中查找要这么转了以后再给FIND
public static String toUnicode(String strvalue)
{
try{
if(strvalue==null)
return null;
else
{
strvalue = new String(strvalue.getBytes("GBK"), "ISO8859-1");
return strvalue;
}
}catch(Exception e){
return null;
}
}
但有一点要保证你的JDBC后面是否加了unicode=true
两种情况
mysql的话怎么加,我在第一篇里给了你
oracle的话怎么加,同MYSQL一样,也可以不加,但关键是你的ORACLE中的字符集必须是alu32
把我的这几篇文章好好看一下,就可以解决JSP中的中文乱码的任何问题了,OK?
<%@
page contentType="text/html;charset=gb2312"
%>里面charset=后面的东西对应上,中文,日文,韩文,西班牙文用这个方法全部通过,无非就是在那边变charset
非常佩服和感谢!!!仔细学习了你有关的讲解。我现在的Oracle字符集是US7ASCII。这怎么办?有没有解决办法?