在网页里面添加数据到MySQL,但是在myeclipse的控制台显示,在数据库里面没有添加进去?

<%@ page language="java" import="java.util.*" contentType="text/html; charset=GBK" pageEncoding="GBK"%>

<%@page import="com.ch6.model.StudentInfo,com.ch6.dal.News" %>

<%

StudentInfo info=new StudentInfo();

News news=new News();

if("add".equals(request.getParameter("action")))

{

info.setName(request.getParameter("name"));

info.setContent(request.getParameter("content"));

info.setDate(request.getParameter("date"));

info.setNumber(request.getParameter("number"));

news.insert(info);

}

 %>



<div class="rightbar">


            <div class="bread"><a href="../index.html">首页</a> >给我留言</div>


                <div class="contact_nei">

               <form id="form1" name="form1" method="post" action="insert.jsp?action=add">

<ul>

   <li>

<label>第几条新闻:</label><input id="Id" name="Id" type="text" class="yuyue_in" /> 

</li>

<li>

<label>您的称呼:</label><input id="name" name="name" type="text" class="yuyue_in" /> 

</li>

<li>

<label>你的留言:</label><textarea id="content" name="content" cols="" rows="" class="yuyue_te"></textarea> 

</li>

<li>

<label>时间日期:</label><input id="date" name="date" type="text" class="yuyue_in" /> 

</li>

<li>

<label>资讯:</label><input id="number" name="number" type="text" class="yuyue_in" />



<li>

<input name="button" id="button" type="submit" value="提交" class="btn" /> <input name="" type="reset" value="重置" class="btn" /> 

</li>

</ul>

</form>



package com.ch6.dal;


import java.sql.*;

import java.util.ArrayList;

import java.util.List;


import com.ch6.Conn;

import com.ch6.model.StudentInfo;


public class News {

Conn conn=new Conn();

//获取资讯

public List<StudentInfo> getList() throws SQLException{

List<StudentInfo> list=new ArrayList<StudentInfo>();

String testdb="select * from news order by number asc";

ResultSet rs=conn.executeQuerry(testdb);

while(rs.next()){

StudentInfo info=new StudentInfo();

info.setId(rs.getInt("Id"));

info.setName(rs.getString("name"));

info.setContent(rs.getString("content"));

info.setDate(rs.getString("date"));

info.setNumber(rs.getString("number"));

list.add(info);

}

conn.close();

return list;

}

public int insert(StudentInfo info){

String testdb="insert into news(name,content,date,number)values";

testdb=testdb+"('"+info.getName()+"','"+info.getContent()

+"','"+info.getDate()+"','"+info.getNumber()+"')";

int result=0;

System.out.println(testdb);

result=conn.executeUpdate(testdb);

conn.close();

return result;

}

}


zhongfm
浏览 1549回答 1
1回答

噼喱啪啦

控制台显示什么
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java