DataBase.java~11~
上传用户:tanyanyong
上传日期:2013-06-23
资源大小:1355k
文件大小:1k
- 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=null;
- 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");
- rs=stmt.executeQuery("select * from BookAdmin");
- while(rs.next()){
- System.out.print("名称: "+rs.getString(1));
- System.out.println();
- }
- }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();
- }catch(Exception e){
- e.printStackTrace();
- }
- }
- }