问答详情
源自:1-1 Servlet概述

用servlet对oracle进行增删改查

怎么用servlet对oracle进行增删改查???请赐教

提问者:颠覆IT 2016-03-31 09:36

个回答

  • 小支
    2016-03-31 19:46:49
    已采纳

    1. 加载驱动2创建连接


      public static Connection getConn() throws SQLException,

      ClassNotFoundException {

      Class.forName("com.mysql.jdbc.Driver");//1

      return DriverManager

      .getConnection(

      "jdbc:mysql://localhost:3306/bookstore?useUnicode=true&characterEncoding=utf-8",

      "root", "password");//2

      }

    3执行语句

    String sql = "select authorise from user where username=? and password = ?";

    pst=con.prepareStatement(sql);

    pst.setString(1, name);

    pst.setString(2, password);

    rs = pst.executeQuery();//查询用这条



    String sql="update book set bookname=?,price=? where id=?";

    pst=con.prepareStatement(sql);

    pst.setString(1, book.getBookname());

    pst.setFloat(2, book.getPrice());

    pst.setInt(3,book.getId());

    count=pst.executeUpdate();//增删改用这条

    4得到结果

    while(rs.next()!=null){}

    5关闭连接

    if (rs != null) {

    rs.close();

    }

    if (pst != null) {

    pst.close();

    }

    if (con != null) {

    con.close();

    }


  • 颠覆IT
    2016-04-01 08:40:33

    是对oracle的操作而不是mysql,具体代码能写一下吗?谢谢

  • 颠覆IT
    2016-04-01 08:18:54

    不需要jsp跳转吗?经理要求不用jsp 可我没试过