当前位置: 代码迷 >> Java Web开发 >> 求JSP对数据库的增删节查小例子
  详细解决方案

求JSP对数据库的增删节查小例子

热度:1689   发布时间:2013-02-25 21:16:42.0
求JSP对数据库的增删改查小例子。
尊敬的个位,由于从C#的桌面程序转到JAVA的JSP的,不怎么会,谁有做好的JSP网页,比如对数据的增删改查功能,其他的暂时估计也用不到, 有的话给我发下,或者给出连接,谢谢了。再次表示感谢下。

------解决方案--------------------------------------------------------
http://wenku.baidu.com/view/9bda64eb172ded630b1cb61b
楼主可以参考下
------解决方案--------------------------------------------------------
这个....
------解决方案--------------------------------------------------------
我空间资源里面有 lz可以去下载 (完整的)
------解决方案--------------------------------------------------------
要的是流程,,,不是代码
------解决方案--------------------------------------------------------
可以找本书看看,或者直接上网搜索jsp+servlet
------解决方案--------------------------------------------------------
由于调用数据库进行增删改查需要进行3层架构,要是在网页上无法解释清楚,你可以选择看网上视频,有很多的.或者买一本书,慢慢研究.
------解决方案--------------------------------------------------------
随便找个WEB项目,都会有这些的
------解决方案--------------------------------------------------------
Java code
// user 添加修改    public static boolean updateUser(int userID, String username,            String password, String sex, String email, String qq, String phone) {        /*         * update user information         */        Connection conn = null;        boolean flag = false;        try {            conn = DB.getConnection();            PreparedStatement ptmt = conn                    .prepareStatement("update user "                            + "set username=?, password=?, sex=?, email=?, qq=?, phone=?"                            + " where userID=?");            ptmt.setString(1, username);            ptmt.setString(2, password);            ptmt.setString(3, sex);            ptmt.setString(4, email);            ptmt.setString(5, qq);            ptmt.setString(6, phone);            ptmt.setInt(7, userID);            ptmt.executeUpdate();            flag = true;        } catch (Exception e) {            flag = false;            e.printStackTrace();        } finally {            DB.closeConnection(conn);        }        return flag;    }//user删除    public static boolean deleteUser(int userID) {        boolean flag = false;        Connection conn = null;        try {            conn = DB.getConnection();            PreparedStatement ptmt = conn                    .prepareStatement("delete from user where userID = ?");            ptmt.setInt(1, userID);            ptmt.executeUpdate();            ptmt.close();            ptmt = conn.prepareStatement("delete from reply where userID = ?");            ptmt.setInt(1, userID);            ptmt.executeUpdate();            ptmt.close();            ptmt = conn.prepareStatement("delete from user where userID = ?");            ptmt.setInt(1, userID);            ptmt.executeUpdate();            flag = true;        } catch (Exception e) {            flag = false;            e.printStackTrace();        } finally {            DB.closeConnection(conn);        }        return flag;    }
------解决方案--------------------------------------------------------
Java code
//DB 类package com.db;import java.sql.Connection;import java.sql.DriverManager;import java.sql.SQLException;public class DB {    public static Connection getConnection() {        Connection conn = null;        try {            String driver = "com.mysql.jdbc.Driver";            String dbURL = "jdbc:mysql://localhost:3306/dbName?useUnicode=true&characterEncoding=UTF-8";            String username = "root";            String password = "";            Class.forName(driver).newInstance();            conn = DriverManager.getConnection(dbURL, username, password);        } catch (SQLException e) {            // TODO: handle exception            e.printStackTrace();        } catch (Exception e) {            // TODO: handle exception            e.printStackTrace();        }        return conn;    }    public static void closeConnection(Connection conn) {        try {            conn.close();        } catch (SQLException e) {            // TODO: handle exception            e.printStackTrace();        } catch (Exception e) {            // TODO: handle exception            e.printStackTrace();        }    }}
  相关解决方案