天津师范大学吧 关注:240,545贴子:3,954,159
  • 3回复贴,共1

【求助】急需一个基于jsp+SQL的系统~~~求求大神们帮帮忙

只看楼主收藏回复

数据库需要~~~请大神们帮帮忙~~~非常感谢


1楼2014-12-23 11:04回复
    jsp:
    <http>
    <body>
    <div>
    <form action=" login" >
    用户名:<input type=" texe" name="username">
    密码:<input type="password" name="password">
    <input type="submit" value="确认登录">
    </form>
    </div>
    </bodt>
    </http>
    servlet:
    import java.sql.*;
    public class DBconn {
    private Connection conn = null;
    private Statement stmt = null;
    private ResultSet rs = null;
    // 创建数据库连接
    private void getConnection() {
    String DBURL = "com.mysql.jdbc.Driver";
    String DBDRIVER = "jdbc:mysql://localhost:3306/数据库名字";
    String DBROOT = "root";
    String DBPWD = "root";
    try {
    Class.forName(DBURL);
    conn = DriverManager.getConnection(DBDRIVER, DBROOT, DBPWD);
    } catch (ClassNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
    // 定义增删改
    public int exeADU(String sql) {
    getConnection();
    try {
    stmt = conn.createStatement(); // 得到statement对象
    int iRS = stmt.executeUpdate(sql);
    return iRS;
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    return -1;
    }
    }
    // 定义查询方法
    public ResultSet exeQuery(String sql) {
    getConnection();
    try {
    stmt = conn.createStatement();
    rs = stmt.executeQuery(sql);
    return rs;
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    return null;
    }
    }
    // 关闭数据库连接
    public void exeClose() {
    if (rs != null) {
    try {
    rs.close();
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
    if (stmt != null) {
    try {
    stmt.close();
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
    if (conn != null) {
    try {
    conn.close();
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
    }
    }


    IP属地:内蒙古2楼2014-12-23 23:04
    回复
      我已放弃
      ——来自 爱贴吧 Windows Phone 客户端


      IP属地:天津来自WindowsPhone客户端3楼2014-12-24 00:44
      回复


        IP属地:北京来自Android客户端4楼2014-12-24 01:16
        回复