读出来转码啊。直接设置数据库字型也可以

解决方案 »

  1.   

    程序(JSP中):
    <%
    Connection con=null;            
    Statement stmt=null;
    ResultSet rs=null; try{
        out.println("start");    %><br><%
        //使用单例模式获得连接         
                      Singleton st=Singleton.getInstance();
                      con=st.getConnect();

        out.println("open");    %><br><%
      
                          stmt = con.createStatement();
        String query = new String();

        out.println("stmt");    %><br><%

        //查询     
        query="select * from user";
        rs=stmt.executeQuery(query);
        out.println("user表中的数据:");     %><br><%
        
        while(rs.next()){
        out.println("--1--");      %><br><%
        String strc=null;
        strc=rs.getString(4);
        out.println("--2--");      %><br><%
         /****************************************/
                                    这一句出问题了,没这一句,可以读出数据库中的数据(但是乱码).
                                    有这一句,Windows下没有问题,Linux下跳到异常中了 
                                    strc=new String(strc.getBytes("ISO8859_1"),"gb2312");
         /****************************************/
         
                                    out.println("--3--");     %><br><%
         out.print(strc);          %><br><%
         out.println("--4--");     %><br><%
           }
        out.println("end");
    }catch(Exception e){
        out.print("--5--"); %><br><%     
        out.print("msg: "+e.getMessage()); %><br><%
    }finally{
    try{
    out.println("close"); %><br><%
    if(null!=rs) rs.close();
    if(null!=stmt) stmt.close();
    if(null!=con) con.close();
    }catch(Exception ex){
    ex.printStackTrace();
    }
    }
    %>结果:
    start 
    open 
    stmt 
    user表中的数据: 
    --1-- 
    --2-- 
    --5--
    msg: null
    close 程序中
    strc=new String(strc.getBytes("ISO8859_1"),"gb2312");
    这一句出问题了,Windows下没有任何问题,Linux下却抛到异常中去了,能解决吗?多谢