您好,欢迎访问三七文档
当前位置:首页 > IT计算机/网络 > 数据库 > java图书管理系统代码
//用户登陆数据库代码:importjava.sql.*;classDatabase{Connectioncon;ResultSetrs;Statementstmt;publicDatabase(){try{Class.forName(sun.jdbc.odbc.JdbcOdbcDriver);//加载JDBC-ODBC桥驱动程序Stringurl=jdbcdbc:HDB;con=DriverManager.getConnection(url);//连接数据库HDB//stmt提供一个创建SQL查询、执行查询、得到返回结果的空间stmt=//con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,//ResultSet.CONCUR_READ_ONLY);}catch(Exceptionex){System.out.println(ex);}}/*根据用户名,获取密码*/publicStringgetPswd(Stringname){try{//rs为执行SQL语句所查询的结果赋给结果集对象rsrs=stmt.executeQuery(SELECTpswdFROMUserWHEREName='+name+');rs.last();//把rs的指针移到最后一行if(rs.getRow()==0){returnnull;}else{StringpswdDB=rs.getString(Pswd);//获取rs结果集中的pswd列的数据returnpswdDB;}}catch(Exceptione){System.out.println(e);returnnull;}}/*增加一行用户名、密码数据*/publicbooleaninsertData(Stringname,Stringpswd){try{Strings=getPswd(name);if(s==null){intrtn=stmt.executeUpdate(INSERTINTOUserVALUES('+name+','+pswd+'));if(rtn!=0)returntrue;}else{returnfalse;}returnfalse;}catch(Exceptionet){System.out.println(et);returnfalse;}}}//进库数据库代码:importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.ResultSet;importjava.sql.Statement;classBookDatabase{Connectioncon;ResultSetrs;Statementstmt;publicBookDatabase(){try{Class.forName(sun.jdbc.odbc.JdbcOdbcDriver);//加载JDBC-ODBC桥驱动程序Stringurl=jdbcdbc:Book;con=DriverManager.getConnection(url);//连接数据库HDB//stmt提供一个创建SQL查询、执行查询、得到返回结果的空间stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);}catch(Exceptionex){System.out.println(ex);}}/*增加一行用户名、密码数据*/publicbooleaninsertData(Stringid,Stringname,Stringwhere,Stringprice,Stringdate){try{intrtn=stmt.executeUpdate(INSERTINTOBookVALUES('+id+','+name+','+where+','+price+','+date+'));if(rtn!=0){returntrue;}else{returnfalse;}}catch(Exceptionet){System.out.println(et);returnfalse;}}/**publicbooleandeleteData(Stringid){try{intrtn=*stmt.executeUpdate(DELETEFROMBookWHEREid=001);if(rtn!=0){*returntrue;}else{returnfalse;}}catch(Exceptione){*System.out.println(e);returnfalse;}}publicbooleanSelect(String*id){try{intrtn=stmt.executeUpdate(SELECT*FROMBookInWHERE*id='+id+');**if(rtn!=0){returntrue;}else{returnfalse;}}catch(Exception*e){System.out.println(e);returnfalse;}}*/}//出库数据库代码:importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.ResultSet;importjava.sql.Statement;classBookDatabase1{Connectioncon;ResultSetrs;Statementstmt;publicBookDatabase1(){try{Class.forName(sun.jdbc.odbc.JdbcOdbcDriver);//加载JDBC-ODBC桥驱动程序Stringurl=jdbcdbc:Book;con=DriverManager.getConnection(url);//连接数据库HDB//stmt提供一个创建SQL查询、执行查询、得到返回结果的空间stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);}catch(Exceptionex){System.out.println(ex);}}/**增加一行用户名、密码数据publicbooleaninsertData(Stringid,Stringname,String*where,String**price,Stringdate){try{intrtn=stmt.executeUpdate(INSERTINTO*BookInVALUES('+id+**','+name+','+where+','+price+','+date+'));**if(rtn!=0){returntrue;}else{returnfalse;}}catch(Exception*et){System.out.println(et);returnfalse;}}*/publicbooleandeleteData(Stringid){try{intrtn=stmt.executeUpdate(DELETEFROMBookWHEREid='+id+');if(rtn!=0){returntrue;}else{returnfalse;}}catch(Exceptione){System.out.println(e);returnfalse;}}/**publicbooleanSelect(Stringid){try{intrtn=*stmt.executeUpdate(SELECT*FROMBookInWHEREid='+id+');if(rtn!=*0){returntrue;}else{returnfalse;}}catch(Exceptione){*System.out.println(e);returnfalse;}}*/}//查询数据库代码;importjava.awt.*;importjava.awt.event.*;importjava.sql.*;importjavax.swing.*;classBookDatabase2extendsJFrame{Stringnumber,name,address,prices,day;Connectioncon;Statementstmt=null;ResultSetresult=null;Stringsql=null;publicBookDatabase2(){try{Class.forName(sun.jdbc.odbc.JdbcOdbcDriver);//加载JDBC-ODBC桥驱动程序Stringurl=jdbc:odbc:Book;con=DriverManager.getConnection(url);//连接数据库HDB//stmt提供一个创建SQL查询、执行查询、得到返回结果的空间stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);}catch(Exceptionex){System.out.println(ex);}}publicvoidselect(Stringid){try{sql=SELECT*FROMBookwhereid='+id+';result=stmt.executeQuery(sql);while(result.next()){number=result.getString(1);name=result.getString(2);address=result.getString(3);prices=result.getString(4);day=result.getString(4);}JOptionPane.showMessageDialog(BookDatabase2.this,成功查询图书!\n+图书ID:+number+\n+图书名称:+name+\n+出版社+address+\n+价格:+prices+\n+出版日期:+day+\n,提示,JOptionPane.ERROR_MESSAGE);}catch(Exceptione){System.out.println(e);}}}
本文标题:java图书管理系统代码
链接地址:https://www.777doc.com/doc-4962823 .html