userbean.java

来自「java编写的与SQL数据连接的好例子~~功能很完善,可以做实训直接交」· Java 代码 · 共 55 行

JAVA
55
字号
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package stuMS;import java.sql.*;import javax.swing.*;/** * * @author Administrator */public class UserBean {    String userId;    String userName;    String password;    String sql;    ResultSet results = null;    public String [][]getAllStuInfo() {        int row =0,i=0,j=0;        String[][]user = null;        Database DB = new Database();        sql = "select * from UserInfo";        try {            DB.OpenConn();            results = DB.executeQuery(sql);                if (results.last()) {                row = results.getRow();            }            if (row == 0) {                user =null;                JOptionPane.showMessageDialog(null, "没有记录!");                return null;            } else {                user = new String[row][3];                results.first();                results.previous();                while (results.next()) {                    for (j = 0; j < 3; j++) {                        user[i][j] = results.getString(j+1);                                            }                                        i++;                    j = 0;                }            }        } catch (Exception e) {            System.out.println(e);        } finally {            DB.closeStmt();            DB.closeConn();        }    return user;}}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?