通过request.getParameter获得中文的数据,然后保存到数据库中,为何在数据库中显示的是乱码。代码如下:
<%@ page contentType="text/html; charset=gb2312"%>
<% request.setCharacterEncoding("GB2312"); %>
<%@ page import="java.sql.*"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<%
String Namejsp=request.getParameter("Name"); String url="jdbc:oracle:thin:@localhost:1521:test";
String user="admin";
String password="admin";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement();
String sql="insert into program values('"+Namejsp+"');
stmt.executeUpdate(sql); <%out.print("数据库操作成功,恭喜你!");%>
<%
rs.close();
stmt.close();
conn.close();
%>
</body>
</html>
<%@ page contentType="text/html; charset=gb2312"%>
<% request.setCharacterEncoding("GB2312"); %>
<%@ page import="java.sql.*"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<%
String Namejsp=request.getParameter("Name"); String url="jdbc:oracle:thin:@localhost:1521:test";
String user="admin";
String password="admin";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement();
String sql="insert into program values('"+Namejsp+"');
stmt.executeUpdate(sql); <%out.print("数据库操作成功,恭喜你!");%>
<%
rs.close();
stmt.close();
conn.close();
%>
</body>
</html>
解决方案 »
- JAVA下socket问题
- jsp页面上怎么用jstl遍历HaspMap哦
- Excel 导出提示打开和保存 jxl
- JSP注释问题
- 广州华工信元通讯技术有限公司 招JAVA程序员
- Tomcat5安装时出现系统错 3,系统找不到指定的路径 急......
- csdn没法用了,请问哪儿有比较大的java技术论坛?
- 请教,<input name="t1" type="text" size="80" value="<%=rs.getString(1)%>">有什么错误!!数据库也是连接对的!
- 关于复选框的问题!
- @value注解
- 多对一的查询,班级表和学生表的查询,查询显示班级,同时显示属于该班学生数,谢谢
- hibernate 查询记录条数
String sql="insert into program values('"+Namejsp+"'); //这条语句能过去吗
<%@ page contentType="text/html; charset=gb2312"%>
<%@ page import="java.sql.*"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<%
request.setCharacterEncoding("GB2312");
String Namejsp=request.getParameter("Name"); String url="jdbc:oracle:thin:@localhost:1521:test";
String user="admin";
String password="admin";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(); String sql="insert into program values('"+Namejsp+"');
stmt.executeUpdate(sql); <%out.print("数据库操作成功,恭喜你!");%>
<%
rs.close();
stmt.close();
conn.close();
%>
</body>
</html>