import java.sql.*;
public class BooksTestJDBC{
public static void main(String[] args)throws Exception{
int option;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// change path to where the database file is stored
String database="jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=E:\\sd\\Books.accdb";
Connection connection=DriverManager.getConnection(database);
do{
System.out.println("0:quit, 1:insert, 2:update price, 3:delete, 4: display");
option=Input.getInteger("select option: ");
switch(option){
case 1: insert(connection);
break;
case 2: update(connection);
break;
case 3: delete(connection);
break;
case 4: display(connection);
}
}while(option!=0);
connection.close();
}
private static void delete(Connection connection) throws Exception{
display(connection);
int id=Input.getInteger("select id: ");
Statement statement=connection.createStatement();
statement.executeUpdate("delete from books where id="+id);
statement.close();
}
private static void display(Connection connection)throws Exception{
Statement statement=connection.createStatement();
ResultSet results=statement.executeQuery("select * from books");
System.out.println(String.format("%-10s%-20s%-30s%10s","ID","AUTHOR","TITLE","PRICE"));
while(results.next())
System.out.println(String.format("%-10s%-20s%-30s%10.2f",results.getInt("Id"),
results.getString("Author"),results.getString("Title"),results.getDouble("Price")));
results.close();
statement.close();
}
private static void insert(Connection connection) throws Exception{
String author=Input.getString("input author: ");
String title=Input.getString("input title: ");
double price=Input.getDouble("input price: ");
Statement statement=connection.createStatement();
statement.executeUpdate("insert into books (author,title,price) values('"+author+"','"+title+"',"+price+")");
statement.close();
}
private static void update(Connection connection) throws Exception{
display(connection);
int id=Input.getInteger("select id: ");
double price=Input.getDouble("input new price: ");
Statement statement=connection.createStatement();
statement.executeUpdate("update books set price="+price+" where id="+id);
statement.close();
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
sample-code.zip_netbean 学生_学生
共73个文件
xml:16个
properties:15个
class:15个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 92 浏览量
2022-09-19
19:13:38
上传
评论
收藏 87KB ZIP 举报
温馨提示
学生成绩管理系统:能输入学科,老师,学生和学生成绩信息,能够处理学生的考试成绩单,用netbean完成
资源详情
资源评论
资源推荐
收起资源包目录
sample-code.zip (73个子文件)
sample code
BooksTestJDBC
test
build.xml 4KB
manifest.mf 85B
src
BooksTestJDBC.java 3KB
Input.java 1KB
nbproject
build-impl.xml 48KB
private
private.xml 354B
private.properties 99B
project.xml 521B
genfiles.properties 475B
project.properties 2KB
build
classes
.netbeans_automatic_build 0B
BooksTestJDBC.class 4KB
Input.class 2KB
CipherClass
Cipher.class 1KB
MessageTestSerialization
test
build.xml 4KB
message.ser 83B
manifest.mf 85B
src
message.ser 76B
Input.java 1KB
MessageTestSerialization.java 690B
Message.java 760B
nbproject
build-impl.xml 48KB
private
private.xml 419B
config.properties 0B
private.properties 326B
project.xml 532B
genfiles.properties 475B
project.properties 3KB
build
classes
.netbeans_automatic_build 0B
MessageTestSerialization.class 1KB
Input.class 2KB
Message.class 1KB
Books.accdb 296KB
PersonTestSerialization
test
build.xml 4KB
manifest.mf 85B
src
Person.java 294B
Input.java 1KB
person.ser 78B
PersonTestSerialization.java 718B
nbproject
build-impl.xml 48KB
private
private.xml 669B
config.properties 0B
private.properties 325B
project.xml 531B
genfiles.properties 475B
project.properties 2KB
build
classes
.netbeans_automatic_build 0B
Person.class 713B
Input.class 2KB
PersonTestSerialization.class 2KB
OrderListTestSerialization
test
build.xml 4KB
manifest.mf 85B
src
orderList.ser 216B
CashOrder.java 760B
CreditOrder.java 484B
Order.java 790B
OrderListTestSerialization.java 2KB
Input.java 1KB
OrderList.java 2KB
nbproject
build-impl.xml 48KB
private
private.xml 1KB
config.properties 0B
private.properties 328B
project.xml 534B
genfiles.properties 475B
project.properties 2KB
build
classes
Order.class 1KB
OrderListTestSerialization.class 3KB
.netbeans_automatic_build 0B
OrderList.class 2KB
Input.class 2KB
CashOrder.class 988B
CreditOrder.class 791B
共 73 条
- 1
刘良运
- 粉丝: 66
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0