日期:2014-05-18  浏览次数:20760 次

请教:如何解决通过JSP页面向SQLServer插入中文字符出现乱码的问题!
我的开发工具是MyEclipse+SQLServer2000

今天遇到通过JSP页面向SQLServer插入中文字符出现乱码的问题,不知如何解决(我已自定义一个转换函数,但还是没用),请各位协助一下,谢谢!

代码如下:

<%@   page   language= "java "   pageEncoding= "UTF-8 "%>
<jsp:directive.page   import= "java.sql.Connection "/>
<jsp:directive.page   import= "java.sql.DriverManager "/>
<jsp:directive.page   import= "java.sql.Statement "/>

<%
String   path   =   request.getContextPath();
String   basePath   =   request.getScheme()+ ":// "+request.getServerName()+ ": "+request.getServerPort()+path+ "/ ";
%>

<!DOCTYPE   HTML   PUBLIC   "-//W3C//DTD   HTML   4.01   Transitional//EN ">
<html>
    <head>
        <base   href= " <%=basePath%> ">
       
        <title> Add </title>
       
<meta   http-equiv= "pragma "   content= "no-cache ">
<meta   http-equiv= "cache-control "   content= "no-cache ">
<meta   http-equiv= "expires "   content= "0 ">        
<meta   http-equiv= "keywords "   content= "keyword1,keyword2,keyword3 ">
<meta   http-equiv= "description "   content= "This   is   my   page ">
<!--
<link   rel= "stylesheet "   type= "text/css "   href= "styles.css ">
-->

    </head>
   
    <body   bgcolor= "lavender ">
        <%
            String   StuID=Bytes(request.getParameter( "StuID "));
            String   StuName=Bytes(request.getParameter( "StuName "));
            String   StuSex=Bytes(request.getParameter( "StuSex "));
            String   StuBirthday=Bytes(request.getParameter( "StuBirthday "));
            String   StuCompany=Bytes(request.getParameter( "StuCompany "));
            String   StuAddress=Bytes(request.getParameter( "StuAddress "));
            String   StuMail=Bytes(request.getParameter( "StuMail "));
            Class.forName( "com.microsoft.sqlserver.jdbc.SQLServerDriver ").newInstance();
        Connection   conn=DriverManager.getConnection( "jdbc:sqlserver://localhost:1433;databaseName=Student ", "sa ", " ");
        Statement   stmt=conn.createStatement();
        String   sql= "INSERT   INTO   Student   VALUES( ' "+StuID+ " ', ' "+StuName+ " ', ' "+StuSex+ " ', ' "+StuBirthday+ " ', ' "+StuCompany+ " ', ' "+StuAddress+ " ', ' "+StuMail+ " ') ";
        int