当前页面: 开发资料首页 → JSP 专题 → 如何把JSP也面中获取的参数写进数据库表中
如何把JSP也面中获取的参数写进数据库表中
摘要: 如何把JSP也面中获取的参数写进数据库表中
我编写了两个JSP页面,一个是获取参数,一个是把获取的参数写进数据表中。源代码如下:
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page pageEncoding="GB2312"%>
<%request.setCharacterEncoding("gb2312");%>
<%@ page import="java.sql.*"%>
HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<head>
增加页面 </head>
<body>
<form action="date.jsp" method="post">
请输入图书信息
编号:<input type=text name=bookid value="">
<input type=submit name=submit value="增加">
<input type=reset name=reset value="取消">
</form>
</body>
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page pageEncoding="GB2312"%>
<%request.setCharacterEncoding("gb2312");%>
<%@ page import="java.sql.*"%>
<head>
update
</head>
<body>
<%String bookid=request.getParameter("bookid");%>
<%
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:sql","CS-K","");
Statement stmt=con.createStatement();
stmt.execute("insert into T_USER(ID)values('bookid')");
stmt.close();
}catch(SQLException ex){}
%>
</body>
运行后到数据库中查看时,发现写进去的不是request.getParameter("bookid")的值,确实bookid。
大虾们请多多指教,谢谢了!
stmt.execute("insert into T_USER(ID)values('" + bookid + "')");