77范文网 - 专业文章范例文档资料分享平台

报刊订阅管理系统 - 课程设计说明书(3)

来源:网络收集 时间:2019-06-11 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

报刊订阅管理系统

userName.addActionListener(this); login.addActionListener(this); register.addActionListener(this); exit.addActionListener(this); }

public static void main(String[] args) {

Main f=new Main();

f.setTitle(\报刊订阅管理系统\ }

public void actionPerformed(ActionEvent e) { // TODO 自动生成的方法存根

if(e.getSource()==register) //注册(登录、退出类似) {

new UsersRegister();//过渡到新的窗口Menu; this.dispose();//释放当前窗口 } }

3.2数据录入实现

录入报刊信息(录入用户信息和对用户、报刊、订单的增删改查与之类似) (1)LoggingdataNewspaper.java

public static void main(String[] args) {

LoggingdataNewspaper f=new LoggingdataNewspaper(); f.setTitle(\报刊信息\ }

public void actionPerformed(ActionEvent e) { // TODO 自动生成的方法存根

if(e.getSource()==button5) // 退出 {

new ManagerHome();//过渡到新的窗口Menu; this.dispose();//释放当前窗口 }

if(e.getSource()==button1) // 添加 {

//定义一个空的newspaper对象 newspaper news=new newspaper(); //将数据封装到news中

news.setNewsNo(text1.getText().trim());

9 / 32

报刊订阅管理系统

news.setNewsName(text2.getText().trim()); news.setPublish(text3.getText().trim()); news.setPubPeriod(text4.getText().trim()); news.setContent(text5.getText().trim());

news.setPrice(Float.parseFloat(text6.getText().trim())); System.out.println(news); //定义一个控制对象

InformationDaoImpl ifd=new InformationDaoImpl(); //执行添加用户操作 ifd.addNews(news); }

if(e.getSource()==button2) // 删除 {

//定义一个空的newspaper对象

newspaper delnews=new newspaper(); //将数据封装到delnews中

delnews.setNewsNo(text1.getText().trim()); delnews.setNewsName(text2.getText().trim());

System.out.println(delnews); //定义一个控制对象

InformationDaoImpl ifd=new InformationDaoImpl(); //执行添加用户操作

ifd.deleteNews(delnews); }

if(e.getSource()==button3) // 查询 {

//定义一个空的newspaper对象 newspaper n=new newspaper(); //将数据封装在n中

String news=text1.getText().trim(); //定义一个控制对象

InformationDaoImpl ifd=new InformationDaoImpl(); n=ifd.FindNewsByNewspaper(news); System.out.println(n);

text2.setText(n.getNewsName()); text3.setText(n.getPublish()); text4.setText(n.getPubPeriod()); text5.setText(n.getContent());

text6.setText(String.valueOf(n.getPrice())); }

if(e.getSource()==button4) // 修改 {

//定义一个空的users对象

10 / 32

报刊订阅管理系统

newspaper news=new newspaper(); //将数据封装到u当中

news.setNewsNo(text1.getText().trim()); news.setNewsName(text2.getText().trim()); news.setPublish(text3.getText().trim()); news.setPubPeriod(text4.getText().trim()); news.setContent(text5.getText().trim());

news.setPrice(Float.parseFloat(text6.getText().trim())); //定义一个控制对象

InformationDaoImpl ifd=new InformationDaoImpl(); //执行修改用户信息操作 ifd.updateNewspaper(news); System.out.println(news); } }

(2)InformationDaoImpl.java //添加报刊

public void addNews(newspaper n){ //定义一个空的连接对象 Connection conn=null; //定义一个准备sql语句 PreparedStatement ps=null; //自定义将要执行的sql语句 String sql=\newspaper(newsNo,newsName,publish,pubPeriod,content,price) values(?,?,?,?,?,?)\

//通过Dbutils得到数据库的连接 conn=Dbutils.getConnection(); System.out.println(conn); try {

//将sql语句传给ps(接收sql语句的容器) ps=conn.prepareStatement(sql); //将news的各个属性值添加到?处 ps.setString(1, n.getNewsNo()); ps.setString(2, n.getNewsName()); ps.setString(3, n.getPublish()); ps.setString(4, n.getPubPeriod()); ps.setString(5, n.getContent()); ps.setFloat(6, n.getPrice());

//执行sql语句(相当于在数据库中执行sql语句) ps.executeUpdate(); } catch (SQLException e) {

// TODO 自动生成的 catch 块

11 / 32

into 报刊订阅管理系统

e.printStackTrace(); }

finally{

//释放连接,同时释放资源

Dbutils.close(conn, ps, null); } }

//通过报刊号和报刊名删除报刊

public void deleteNews(newspaper dn) { // TODO 自动生成的方法存根 Connection conn=null;

PreparedStatement ps=null; conn=Dbutils.getConnection(); String sql=\from newspaper where newsNo=? and newsName=?\ try {

ps=conn.prepareStatement(sql); ps.setString(1, dn.getNewsNo()); ps.setString(2, dn.getNewsName()); ps.executeUpdate(); } catch (SQLException e) {

// TODO 自动生成的 catch 块 e.printStackTrace(); }finally {

Dbutils.close(conn, ps, null); } }

//通过报刊代号查找报刊

public newspaper FindNewsByNewspaper(String ne) { newspaper news= new newspaper(); Connection conn=null;

PreparedStatement ps=null; ResultSet rs=null;

conn=Dbutils.getConnection();

String sql=\ try {

ps=conn.prepareStatement(sql); ps.setString(1, ne); rs=ps.executeQuery(); if(rs.next()) {

news.setNewsNo(rs.getString(\

12 / 32

报刊订阅管理系统

news.setNewsName(rs.getString(\ news.setPublish(rs.getString(\

news.setPubPeriod(rs.getString(\ news.setContent(rs.getString(\ news.setPrice(rs.getFloat(\ }

} catch (SQLException e) {

// TODO 自动生成的 catch 块 e.printStackTrace(); }finally {

Dbutils.close(conn, ps, rs); }

return news;

//更新报刊信息

public void updateNewspaper(newspaper news) { // TODO Auto-generated method stub //定义一个空的连接对象 Connection conn=null; //定义一个准备sql语句 PreparedStatement ps=null; //自定义将要执行的sql语句

String sql=\newspaper set publish=? content=?, price=? where newsNo=? and newsName=? \ //通过Dbutils得到数据库的连接 conn=Dbutils.getConnection(); System.out.println(conn); try {

//将sql语句传给ps(接收sql语句的容器) ps=conn.prepareStatement(sql); //将user的各个属性值添加到?处 ps.setString(1, news.getPublish()); ps.setString(2, news.getPubPeriod()); ps.setString(3, news.getContent()); ps.setFloat(4, news.getPrice()); ps.setString(5,news.getNewsNo()); ps.setString(6, news.getNewsName()); //执行update SQL语句 ps.executeUpdate(); } catch (SQLException e) {

// TODO 自动生成的 catch 块 e.printStackTrace(); }

13 / 32

,pubPeriod=?,

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库报刊订阅管理系统 - 课程设计说明书(3)在线全文阅读。

报刊订阅管理系统 - 课程设计说明书(3).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/zonghe/656515.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: