求jsp+javaBean连数据库实现单表增删改查功能的源程序代码
代码简洁有注释更好,学习用。我的邮件是noryaland@gmail.com --------------------编程问答-------------------- 不能沉 --------------------编程问答-------------------- 我们学校有这个 我去给你找找 一年多了 不知道放哪里去了 呵呵 --------------------编程问答-------------------- 看来是没什么用 被我删了 不好意思 --------------------编程问答-------------------- 求一份代码,用以研习。 --------------------编程问答-------------------- 同求呵呵 --------------------编程问答-------------------- www.pudn.com --------------------编程问答-------------------- 数据库最好是oracle或sqlserver,因为我只懂这两种 --------------------编程问答-------------------- 代码到,给分 --------------------编程问答-------------------- 随便到网上找一下就有了 --------------------编程问答-------------------- http://hi.baidu.com/wzqiajng/blog/item/e7ad87dfda6769c08d1029ad.html
这个行不行 --------------------编程问答--------------------
这是Struts的 --------------------编程问答-------------------- 有没有邮箱或者qq,我的是295472899,我直接发你 --------------------编程问答-------------------- 可以考虑学习Hibernate,无论是连接数据库,还是对数据库进行增删改查都很方便。。。。。。。。。 --------------------编程问答-------------------- 网上一搜一大把 --------------------编程问答--------------------
我的邮箱是noryaland@gmail.com ,请发给我,谢谢 --------------------编程问答--------------------
我是要一个完整的实例,以便研习 --------------------编程问答-------------------- 留言板一类的也可以,最好有程序说明 --------------------编程问答-------------------- 我有一份,是产品管理,前两个星期刚做的,用的是oracle数据库~~~要不?要的话发信息到我邮箱:942581269@qq.com --------------------编程问答-------------------- 我只要一份简单完整的例子就可以 --------------------编程问答-------------------- 唉,这个。。。要交作业了?。。。大家还是自己做吧! --------------------编程问答-------------------- 网上多的很,你自己配个JDBC或odbc多可以。 --------------------编程问答-------------------- 这个真心不是太难..这也太懒了 --------------------编程问答-------------------- 不懂问我
需要在sqlserver2000里建立一个表
create table T1
(
T1_ID int primary key identity(1,1),
T1_C1 varchar(50),
T1_C2 varchar(50)
)
http://www.stpbk.com/databasedemo.rar --------------------编程问答-------------------- 可以 给我 发一份不 407082303@qq.com --------------------编程问答-------------------- javabean 自己写 servlet自己写 增删改自己写 百度 谷歌一大把 不就完成了? --------------------编程问答-------------------- 我的资源有一份jsp+sevlelt+javabean+mysql的留言板 --------------------编程问答-------------------- 很久没写过了 。都是以前做过的东西,快忘光了 --------------------编程问答-------------------- try {
Class.forName("com.mysql.jdbc.Driver");
}
catch(ClassNotFoundException e){}
String insertCondition=构造sql语句;
String str="";
Connection con;
Statement sql;
try { String uri="jdbc:mysql://localhost/gjk";
con=DriverManager.getConnection(uri,"root","t");
sql=con.createStatement();
sql.executeUpdate(insertCondition);
}
catch(SQLException e)
{
} --------------------编程问答-------------------- 楼主这是最基本的哦最好自己做一下,很简单的,即使是刚学java一个学期的学生也能做出来的 --------------------编程问答-------------------- 谁有完整的实例,不要servlet,struts,同求 --------------------编程问答--------------------
package com.action;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.bean.T1Bean;
import com.bo.T1Bo;
public class Action extends HttpServlet {
private T1Bo bo;
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// response.setContentType("text/html");
// PrintWriter out = response.getWriter();
// out
// .println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
// out.println("<HTML>");
// out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
// out.println(" <BODY>");
// out.print(" This is ");
// out.print(this.getClass());
// out.println(", using the GET method");
// out.println(" </BODY>");
// out.println("</HTML>");
// out.flush();
// out.close();
doPost(request, response);
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// response.setContentType("text/html");
// PrintWriter out = response.getWriter();
// out
// .println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
// out.println("<HTML>");
// out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
// out.println(" <BODY>");
// out.print(" This is ");
// out.print(this.getClass());
// out.println(", using the POST method");
// out.println(" </BODY>");
// out.println("</HTML>");
// out.flush();
// out.close();
bo = new T1Bo();
String method = request.getParameter("method");
if(method == null || method.equals("getData"))
{
try {
// ��BO�л�ȡ���
List<T1Bean> list = bo.getData();
// ����request��
request.setAttribute("data", list);
// ��ת��index.jsp
RequestDispatcher rd = request.getRequestDispatcher("index.jsp");
rd.forward(request, response);
} catch (ClassNotFoundException e) {
// TODO �Զ���� catch ��
e.printStackTrace();
} catch (SQLException e) {
// TODO �Զ���� catch ��
e.printStackTrace();
}
}
else if(method.equals("save"))
{
try {
T1Bean bean = new T1Bean();
bean.setT1_C1(request.getParameter("c1"));
bean.setT1_C2(request.getParameter("c2"));
bo.addData(bean);
response.sendRedirect("Action");
} catch (ClassNotFoundException e) {
// TODO �Զ���� catch ��
e.printStackTrace();
} catch (SQLException e) {
// TODO �Զ���� catch ��
e.printStackTrace();
}
}
else if(method.equals("remove"))
{
try {
T1Bean bean = new T1Bean();
bean.setT1_ID(Integer.parseInt(request.getParameter("id")));
bo.delData(bean);
response.sendRedirect("Action");
} catch (ClassNotFoundException e) {
// TODO �Զ���� catch ��
e.printStackTrace();
} catch (SQLException e) {
// TODO �Զ���� catch ��
e.printStackTrace();
}
}
}
}
你这个文件是干什么用的,怎么是Action继承servlet,模仿struts吗??????????????? --------------------编程问答-------------------- 有点复杂了,我只想要简单而且公司里商业化的。 --------------------编程问答-------------------- 我把一个简单完整的代码研习好了,好去应聘啊。我不是交作业的。我早毕业了。 --------------------编程问答--------------------
找一份简单,商业的,吃透就好,你就能独挡一面 --------------------编程问答-------------------- http://topic.csdn.net/u/20111123/21/3e1f9a1a-9c1a-4384-8af7-bdd563938dc5.html
去看看这里吧,我前几天发的代码,jsp+javabean+sql2008实现了插入的功能,我想查询删除只是加几条语句了不难吧,不懂的还可以问我,我把web工程发给你 --------------------编程问答-------------------- 不用oracle数据库。不用框架。单纯的实现增删改查的例子有木有啊。。着急!!!!! --------------------编程问答-------------------- 有的可以发我邮箱312721323@qq.com --------------------编程问答-------------------- 这个只适合出学者,增删改查有点类同,楼主要学会举一反三。
package oper;
import java.sql.*;
import java.util.ArrayList;
import voo.Userinfo;
import conn.DbConn;
public class UserInfoOper {
//查询单个用户的方法
public Userinfo selectOne(int userid){
Connection conn = null;
try {
conn = DbConn.getConn();
String sql = "select * from userinfo where userid=?";
PreparedStatement pstmt =
conn.prepareStatement(sql);
pstmt.setInt(1,userid);
ResultSet rs = pstmt.executeQuery();
rs.next();
Userinfo ui = new Userinfo();
ui.setUserid(rs.getInt(1));
ui.setUname(rs.getString(2));
ui.setUpass(rs.getString(3));
ui.setUser易做图(rs.getString(4));
ui.setUserage(rs.getInt(5));
ui.setUseradd(rs.getString(6));
return ui;
} catch (Exception e) {
// TODO 自动生成 catch 块
e.printStackTrace();
return null;
} finally{
if(conn!=null)
try {
conn.close();
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
}
//查询方法
public ArrayList selectAll(){
Connection conn = null;
try {
conn = DbConn.getConn();
String sql = "select * from userinfo";
PreparedStatement pstmt =
conn.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
ArrayList al = new ArrayList();
while(rs.next()){
Userinfo ui = new Userinfo();
ui.setUserid(rs.getInt(1));
ui.setUname(rs.getString(2));
ui.setUpass(rs.getString(3));
ui.setUser易做图(rs.getString(4));
ui.setUserage(rs.getInt(5));
ui.setUseradd(rs.getString(6));
ui.setPhotopath(rs.getString(8));
al.add(ui);
}
return al;
} catch (Exception e) {
// TODO 自动生成 catch 块
e.printStackTrace();
return null;
} finally{
if(conn!=null)
try {
conn.close();
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
}
//增加方法
public void insert(Userinfo ui){
Connection conn = null;
try {
conn = DbConn.getConn();
String sql = "insert into userinfo(username,userpass,user易做图,userage,useradd,photopath) values (?,?,?,?,?,?)";
PreparedStatement pstmt =
conn.prepareStatement(sql);
pstmt.setString(1,ui.getUname());
pstmt.setString(2,ui.getUpass());
pstmt.setString(3,ui.getUser易做图());
pstmt.setInt(4,ui.getUserage());
pstmt.setString(5,ui.getUseradd());
pstmt.setString(6,ui.getPhotopath());
pstmt.executeUpdate();
} catch (Exception e) {
// TODO 自动生成 catch 块
e.printStackTrace();
} finally{
if(conn!=null)
try {
conn.close();
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
}
//删除
public void delete(int userid){
Connection conn = null;
try {
conn = DbConn.getConn();
String sql = "delete from userinfo where userid = ?";
PreparedStatement pstmt =
conn.prepareStatement(sql);
pstmt.setInt(1,userid);
pstmt.executeUpdate();
} catch (Exception e) {
// TODO 自动生成 catch 块
e.printStackTrace();
} finally{
if(conn!=null)
try {
conn.close();
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
}
//修改
public void update(Userinfo ui){
Connection conn = null;
try {
conn = DbConn.getConn();
String sql = "UPDATE USERINFO set username=?,userpass=?,user易做图=?,userage=?,useradd=? where userid=?";
PreparedStatement pstmt =
conn.prepareStatement(sql);
pstmt.setString(1,ui.getUname());
pstmt.setString(2,ui.getUpass());
pstmt.setString(3,ui.getUser易做图());
pstmt.setInt(4,ui.getUserage());
pstmt.setString(5,ui.getUseradd());
pstmt.setInt(6,ui.getUserid());
pstmt.executeUpdate();
} catch (Exception e) {
// TODO 自动生成 catch 块
e.printStackTrace();
} finally{
if(conn!=null)
try {
conn.close();
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
}
//判断用户名和密码是否存在
public boolean check(Userinfo ui){
Connection conn = null;
try {
conn = DbConn.getConn();
String sql = "select count(*) from userinfo where username=? and userpass=?";
PreparedStatement pstmt =
conn.prepareStatement(sql);
pstmt.setString(1,ui.getUname());
pstmt.setString(2,ui.getUpass());
ResultSet rs = pstmt.executeQuery();
rs.next();
int n = rs.getInt(1);
if(n>0) return true;
else
return false;
} catch (Exception e) {
// TODO 自动生成 catch 块
e.printStackTrace();
return false;
} finally{
if(conn!=null)
try {
conn.close();
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
}
}
补充:Java , Web 开发