图书管理系统
来源:互联网 发布:人工智能的文献综述 编辑:程序博客网 时间:2024/05/24 05:53
package
librarySystem;
import
java.sql.*;
import
java.util.*;
/*
* 图书表模型
* */
import javax.swing.table.*;
@SuppressWarnings("serial")
public class BookTableModel extends AbstractTableModel{
//表的元素
private Vector<Vector<String>> rowData;
private Vector<String> colName;
// 数据库
private PreparedStatement stmt;
private ResultSet result;
public BookTableModel(String sql) throws SQLException{
this.initData(sql);
}
public BookTableModel() throws SQLException{
this.initData("SELECT * FROM book_info");
}
public void initData(String sql) throws SQLException{
setRowData(new Vector<Vector<String>>());
setColName(new Vector<String>());
getColName().add("书号");
getColName().add("书名");
getColName().add("作者");
getColName().add("出版社");
getColName().add("出版时间");
getColName().add("价格");
/*
* 数据库的导入
* */
try
{
Class.forName(
"com.mysql.jdbc.Driver"
);
}
catch
(ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String url=
"jdbc:mysql://localhost:3306/device"
;
String user=
"root"
;
String password=
"zjq1314520"
;
Connection con=DriverManager.getConnection(url,user,password);
stmt = con.prepareStatement(sql);
result=stmt.executeQuery();
importSQL();
}
void
importSQL()
throws
SQLException{
// TODO Auto-generated method stub
@SuppressWarnings
(
"unused"
)
boolean
signNull=
true
;
while
(result.next()){
Vector<String> item=
new
Vector<String>();
for
(
int
i=
1
;i<
7
;i++){
item.add(result.getString(i));
}
getRowData().add(item);
signNull=
false
;
}
result.close();
}
@Override
public
int
getColumnCount() {
//得到列数
// TODO Auto-generated method stub
return
this
.colName.size();
}
@Override
public
int
getRowCount() {
//得到行数
// TODO Auto-generated method stub
return
this
.rowData.size();
}
@Override
public
Object getValueAt(
int
row,
int
col) {
//得到某行某列的数据
// TODO Auto-generated method stub
return
(
this
.rowData.get(row)).get(col);
}
@Override
public
String getColumnName(
int
column) {
// TODO Auto-generated method stub
return
this
.colName.get(column);
}
public
Vector<Vector<String>> getRowData() {
return
rowData;
}
public
void
setRowData(Vector<Vector<String>> rowData) {
this
.rowData = rowData;
}
public
Vector<String> getColName() {
return
colName;
}
public
void
setColName(Vector<String> colName) {
this
.colName = colName;
}
public
void
addBook(String sql){
try
{
stmt.executeUpdate(sql);
}
catch
(SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// initData("SELECT * FROM book_info");
}
public
void
deleteBook(String sql){
try
{
stmt.executeUpdate(sql);
}
catch
(SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
0 0
- 图书管理系统论文
- 图书管理系统(1)
- 图书管理系统(2)
- 图书管理系统(3)
- java-图书管理系统
- 图书管理系统
- 图书管理系统
- 简单图书管理系统
- 图书管理系统
- 图书管理系统
- 图书仓库管理系统
- 《图书管理系统》毕业论文
- 图书管理系统
- 图书管理系统
- 图书管理系统
- 图书管理系统
- 图书管理系统
- 图书管理系统
- 新浪微博发布效果
- 浮动框架iframe元素
- 从零开始学网络爬虫之BeautifulSoap
- 快速认识ELK中的L - Logstash
- 匀速运动
- 图书管理系统
- 伸缩菜单
- Hadoop平台中SQL优化的四个思路
- 从中心放大
- c++ 中__declspec 的用法
- 第十五周OJ——2886大写变小写
- Java被忽略的基本知识(一)
- Java/Android 常面面试题抽取
- 深入理解js的prototype以及prototype的一些应用