日期:2014-05-20  浏览次数:20762 次

jsp接收数据写入oracle数据库
html提交数据:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
 <meta http-equiv=Content-Type content="text/html;charset=utf-8">
  <title> 报名系统 </title>
  <meta name="Generator" content="EditPlus">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
 </head>
<h2 align = 'center'>院新生才艺大赛报名系统</h2>
<hr>
<body>
<form method="post" action = "date.jsp" >
姓名:<input type="text" name="stuname" id="stuname">
<br><br>
学号:<input type="text" name="stunum" id="stumun">
<br><br>
性别:<select name="sex">
<option value="男"selected>男
<option value="女">女
</select>
<br><br>
出生年月:<select name="biryear">
<option value="1988" selected>1988
<option value="1989">1989
<option value="1990">1990
<option value="1991">1991
<option value="1992">1992
<option value="1993">1993
<option value="1994">1994
<option value="1995">1995
</select>年
<select name="birmonth">
<option value="1" selected>1
<option value="2">2
<option value="3">3
<option value="4">4
<option value="5">5
<option value="6">6
<option value="7">7
<option value="8">8
<option value="9">9
<option value="10">10
<option value="11">11
<option value="12">12
</select>月
<br><br>
政治面貌:<select name="mianmao">
<option value="团员" selected>团员
<option value="群众">群众
<option value="党员">党员
</select>
<br><br>
民族:<input type="text" name="nation">
<br><br>
籍贯:<input type="text" name="home">
<br><br>
专业班级:<select name="major">
<option value="计算机" selected>计算机
<option value="计科">计科
<option value="通信">通信
<option value="信安">信安
<option value="网工">网工
<option value="中加">中加
</select>
<select name="stuclass">
<option value="1" selected>1
<option value="2">2
<option value="3">3
<option value="4">4
<option value="5">5
<option value="6">6
</select>班
<br><br>
特长:<input type="text" name="techang">
<br><br>
联系方式:<input type="text" name="tel">
<br><br>
参赛类别:<select name="choose">
<option value="声乐" selected>声乐
<option value="器乐">器乐
<option value="主持">主持
<option value="舞蹈">舞蹈
<option value="曲艺">曲艺
<option value="其他">其他
</select>
<br><br>
个人介绍:
<br><br>
<textarea name="introduce" rows="10" cols=""></textarea>
<br><br>
<input type="submit" value="提交">
</form>
<p align = 'center'>&copy;&nbsp;2011 <b>SIPC</b>&nbsp;版权所有 By:McDong</p>
 </body>
</html>



jsp代码:


<%@ page import="java.sql.*"%>
<%!
public static final String DBDRIVER = "oracle.jdbc.driver.OracleDriver" ;
public static final String DBURL = "jdbc:oracle:thin:@localhost:1521:orcl" ;
public static final String DBUSER = "scott" ;
public static final String DBPASS = "admin" ;
%>
<%
Connection conn = null ;
PreparedStatement pstmt = null ;
ResultSet rs = null ;
Statement sm = null;  

%>
<%
String stuname = request.getParameter("stuname") ; // 接收表单参数
String stumun = request.getParameter("stumun") ; // 接收表单参数
String sex = request.getParameter("sex") ;
String biryear = request.getParameter("biryear") ;
String birmon = request.getParameter("birmon") ;
String mianmao = request.getParameter("mianmao") ;
String nation = request.getParameter("nation") ;
String home = request.getParameter("home") ;
String major = request.getParameter("major") ;
String stuclass = request.getParameter("stuclass") ;
String techang = request.getParameter("techang") ;
String tel = request.getParameter("tel") ;
String choose = request.getParameter("choose") ;
String numberroduce = request.getParameter("numberroduce") ;
%>
<%
  conn = DriverManager.getConnection(DBURL,DBUSER,DBPASS) ;
  String insert = "insert into apply values('"+stuname+"',"+stumun+",'"+sex+"','"+biryear+"','"+birmon+"','"+mianmao+"','"+nation+"','"+home+"','"+major+"','"+stuclass+"','"+techang+"','"+tel+"','"+choose+"','"+numberroduce+"')";

%>


之后应该怎么写入数据库? 已经写出了sql语句,后边不回了,网上的没看明白,麻烦大家了...

------解决方案--------------------
楼主用得jdbc吧 到conn = DriverManager.getConnection(DBURL,DBUSER,DBPASS) ;
这一步,你已经获取数据库连接了 之后就按jdbc的那6步走呗:
①加载驱动
②得到连接

--------------------------------------------
③获取Statement
④准备sql操作数据库
⑤得到结果集
⑥关闭资源

接下来你获取statement对象,执行SQL语句,得到结果集,最后关闭连接 就ok了