DataBase.java
资源名称:bookshop.zip [点击查看]
上传用户:sxlinghang
上传日期:2022-07-20
资源大小:1405k
文件大小:1k
源码类别:
数据库编程
开发平台:
Java
- package bookshop.util;
- /**
- * <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() {
- this.connect();
- }
- 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);
- stmt = conn.createStatement ();
- }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();
- }
- }
- }