您现在的位置:计算机技术学习网 > 技术中心 > WEB编程 > JSP >

JSP中的数据库操作(3):JSP页面中的数据库插入

来源:未知 责任编辑:责任编辑 发表时间:2015-01-01 13:16 点击:

这次是怎样将大象放冰箱的命题了!大家都懂的!

我们要解决的主要有两个问题:

1、如何获取输入的内容

2、如何插入时间。

直接上代码

[html] 
<%@ page language="java" import="java.util.*, java.sql.*" pageEncoding="gb2312"%> 
<% 
String path = request.getContextPath(); 
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 
%> 
<%request.setCharacterEncoding("UTF-8");%>  
<%response.setCharacterEncoding("UTF-8");%>  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
 
<style type="text/css"> 
table{ width:800px; margin:auto; padding: 5px; font-size:12px; border:0px; background:#00CCFF;} 
tr{ background:#fff;} 
td{ padding: 5px;} 
#title{ text-align:center;} 
</style> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
<title>无标题文档11</title> 
</head> 
 
<body> 
 <form method=post> 
    标题:<input type="text" name="title"/><br/> 
    内容:<input type="text" name="content"/><br/> 
    <input type="submit" value="提交" /> 
 </form> 
 <% 
 //连接MySQL数据库  
    Class.forName("com.mysql.jdbc.Driver").newInstance(); 
    String url="jdbc:mysql://localhost:3306/news"; 
    String user="root"; 
    String password="1234"; 
    Connection conn = DriverManager.getConnection(url, user, password); 
    Statement st = conn.createStatement(); 
     
 %> 
    <table > 
  <tr> 
    <td width="174" id="title">标题</td> 
    <td width="449" id="title">内容</td> 
    <td width="161" id="title">时间</td> 
  </tr> 
     
<% 
     
    ResultSet rs = st.executeQuery("SELECT * FROM data ORDER BY id DESC LIMIT 10"); 

发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
用户名: 验证码:点击我更换图片
最新评论 更多>>

推荐热点

  • JSP与Servlet
  • 自己动手写MiniBBS系列(基本篇)之用户登录
  • JSP取当前日期
  • JDBC 入门(一)
  • 打开一个jsp页面默认查询所有数据,调用action
  • 使用JSP标签库验证用户的输入(2)完
  • WIN98/2000下的jsp服务器
  • 自定义JSP标签(tag)浅议
  • Struts学习傻瓜式入门篇
网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
Copyright © 2008-2015 计算机技术学习交流网. 版权所有

豫ICP备11007008号-1