java web中连接数据库连接,关于javaweb项目中连接数据库的有关问题!

当前位置:我的异常网» Java Web开发 » 关于javaweb项目中连接数据库的有关问题!

关于javaweb项目中连接数据库的有关问题!

www.myexceptions.net  网友分享于:2013-03-25  浏览:21次

关于javaweb项目中连接数据库的问题!!

亲们!最近在学JavaWeb,感觉有点蛋疼。只能向大家求助了,改了一上午的代码,系统提示没有任何错误,但是在运行的时候总是达不到效果,下面我把代码罗列出来,大家帮我解决解决!我采用的MVC开发模式:

servlet代码:

package servlet;

import java.io.IOException;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import bean.CtrlSql;

import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.Date;

public class AddVistList extends HttpServlet {

private static final long serialVersionUID=1L;

public void doGet(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

response.setContentType("text/html");

CtrlSql con=new CtrlSql(); //实例化数据库操作类

String radio=request.getParameter("radio");

if (radio.equals("yes")) {

radio="是";

}

else {

radio="否";

}

String address=new String(request.getParameter("address").getBytes("iso8859-1"));

if (address==null) {

address="成都";

}

String name=new String(request.getParameter("name").getBytes("iso8859-1"));

String text=new String(request.getParameter("text").getBytes("iso8859-1"));

DateFormat df=new SimpleDateFormat("yyyy-m-dd HH:mm:ss");

//定义格式化日期的格式

System.out.println("现在开始添加数据!!");

String date=df.format(new Date()); //格式化当前的时间,并赋给date

String sql="insert into 'laifang' values('" //(lf_name,lf_riqi,lf_liuyan,lf_gz,lf_address)

+name

+"','"

+date

+"','"

+text

+"','"

+radio

+"','"

+address+

"')";

//根据获得信息生成插入SQL语句

con.con(); //连接到数据库

con.update(sql); //执行SQl语句

response.sendRedirect("../iframe/message.jsp");//页面转向

}

public void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

}

}

下面这是jsp页面代码:

你是否是本校工作人员?

你来自什么地方:

-请选择你所在的城市-

成都

攀枝花

南充

乐山

泸州

文章评论

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值