DataBase.java~8~
资源名称:bookshop.zip [点击查看]
上传用户:sxlinghang
上传日期:2022-07-20
资源大小:1405k
文件大小:1k
源码类别:
数据库编程
开发平台:
Java
- package bookshop.util;
- /**
- * <p>数据专用包 </p>
- * <p>负责数据库的连接,数据的插入更新和删除 </p>
- * <p>Copyright: wxy Copyright (c) 2004</p>
- * <p>Company:juanjuan book shop online </p>
- * @by :wxy
- * @version 1.0
- */
- import java.sql.*;
- public class DataBase {
- public Connection conn;
- public Statement stmt;
- public ResultSet rs;
- public String sqlStr="";
- public DataBase() {
- }
- public boolean connect(){
- try{
- Class.forName("org.gjt.mm.mysql.Driver").newInstance();
- String url ="jdbc:mysql://localhost/BookStore?user=wxy&useUnicode=true&characterEncoding=8859_1";
- conn=DriverManager.getConnection(url);
- System.out.print("7777777777");
- stmt = conn.createStatement ();
- System.out.print("44444422222");
- }catch(Exception ee){
- System.out.println("connect db error:"+ee.getMessage());
- return false;
- }
- return true;
- }
- public static void main(String[] args) {
- try{
- DataBase db = new DataBase();
- db.connect();
- Statement stmt=db.conn.createStatement();
- ResultSet rs=stmt.executeQuery("select * from BookAdmin");
- while(rs.next()){
- System.out.print("名称: "+rs.getString(1));
- System.out.print("tpassword: "+rs.getString(2));
- System.out.println();
- }
- }catch(Exception e){
- e.printStackTrace();
- }
- }
- }