我在连接数据库的时候,传递中文会出现乱码!!
只有中文会,其余则不会,请问这是什么问题,以下是我的源码。
select.jsp
<%@ page contentType="text/html;charset=gb2312" %>
<%@ page language="java" %>
<HTML>
<head>
<title>欢迎来到数据库查询页面</title>
</head>
<body>
<form action=selecdb.jsp method=post>
<input type="text" name="U_Name">
<input type="submit" value="发送">
</form>
</body>
selecdb.jsp
<%@ page contentType="text/html;charset=gb2312" %>
<%@ page language="java" %>
<%@ page import="java.sql.*" %>
<html>
<head>
<title>欢迎来到JSP数据库插入页面</title>
<META http-equiv="Content-Type" content="text/html;
charset=GB2312">
</head>
<%!
String DriverName,DBName,query,Name,Pwd;
Connection conn;
Statement stmt;
ResultSet rs;
%>
<% DriverName="sun.jdbc.odbc.JdbcOdbcDriver";
DBName="jdbc
dbc:userdb";
Class.forName(DriverName);
conn=DriverManager.getConnection(DBName,"","");
stmt=conn.createStatement();
Name=request.getParameter("U_Name");
out.println(Name+"<BR>");
query="select * from User where UserName='"+Name.trim()+"'";
out.println(query);
rs=stmt.executeQuery(query);
%>
<br>
<%
out.println("一切都好!"+"<BR>");
if(rs!=null){
while(rs.next())
{
String UserName=rs.getString("UserName");
String Pwd=rs.getString("UserPwd");
out.println("用户名:"+UserName+"<BR>");
out.println(" 密码:"+Pwd+"<BR>");
}
}
rs.close();
stmt.close();
conn.close();
%>
<body>
</body>
</html>
在IE中出现:
??????
select * from User where UserName='??????'
一切都好!a