mysql数据库连接标准操作

import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException;

public class DataBaseConnection {  private static final String DBDRIVER = "org.gjt.mm.mysql.Driver" ;  private static final String DBURL = "jdbc:mysql://localhost:3306/mldn" ;  private static final String DBUSER = "root" ;  private static final String DBPASS = "mysqladmin" ;  private Connection conn = null ;  public DataBaseConnection(){   try {    Class.forName(DBDRIVER) ;   } catch (ClassNotFoundException e) {    // TODO Auto-generated catch block    e.printStackTrace();   }   try {    conn = DriverManager.getConnection(DBURL, DBUSER,DBPASS) ;   } catch (SQLException e) {    // TODO Auto-generated catch block    e.printStackTrace();   }  }  public Connection getConnection(){   return this.conn ;  }  public void close(){   if(this.conn!=null){    try {     this.conn.close() ;    } catch (SQLException e) {     // TODO Auto-generated catch block     e.printStackTrace();    }   }  } }

posted @ 2013-10-27 21:36  502ck  阅读(170)  评论(0编辑  收藏  举报