📄 titleinfowindow.java
字号:
package newLibrary;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.*;
import java.sql.*;
public class TitleInfoWindow extends JFrame
{
String strurl;
Connection conn;
Statement stmt;
ResultSet rs;
Object a[][]= new Object[60][9];
Object columnName[]={"书号","系别","出版社","书名","借出","出版日期","作者","图书分类","备注"};
private JPanel ContentPane;
private JButton exit = new JButton("关闭");
private JTable table = new JTable(a, columnName);
public TitleInfoWindow()
{
Container con = getContentPane();
con.setLayout(new FlowLayout());
this.setBounds(250,50,490,500);
this.setTitle("所有图书信息");
exit.addActionListener(new Exit());
exit.setBounds(800,500,80,30);
con.add(exit);
con.add(table);
Container container = getContentPane(); //创建一个面板
container.add(new JScrollPane(table),FlowLayout.LEFT); //添加滚动窗口到面板上
this.setVisible(true); //设里窗体可见
this.validate();
//显示全部信息
int i = 0;
while(i>=0) { //清空上次查询结果
a[i][0] = "";
a[i][1] = "";
a[i][2] = "";
a[i][3] = "";
a[i][4] = "";
a[i][5] = "";
a[i][6] = "";
a[i][7] = "";
a[i][8] = "";
i--;
}
repaint();
i = 0;
try {
String strurl ="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=student.mdb";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection(strurl);
Statement stmt = conn.createStatement();
rs=stmt.executeQuery("Select * From StuInfo");//显示表中的全部记录
while(rs.next())
{ //处理查询过程
String 书号 = rs.getString("书号");//从数据库表中取出一个记录的书号字段
String 系别 = rs.getString("系别");
String 出版社 = rs.getString("出版社");
String 书名 = rs.getString("书名");
String 借出 = rs.getString("借出");
String 出版日期 = rs.getString("出版日期");
String 作者 = rs.getString("作者");
String 图书分类 = rs.getString("图书分类");
String 备注 = rs.getString("备注");
a[i][0] = 书号; //将字段写入表格中
a[i][1] = 系别;
a[i][2] = 出版社;
a[i][3] = 书名;
a[i][4] = 借出;
a[i][5] = 出版日期;
a[i][6] = 作者;
a[i][7] = 图书分类;
a[i][8] = 备注;
i++;
}
}
catch(Exception e1){
}
}
class Exit implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
dispose();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -