zoukankan      html  css  js  c++  java
  • java web中常用的mysql连接数据库的语句

    java web中,常用的mysql连接数库,除了需要配置好驱动程序,还有一点很重要的就是要经常会使用到这些语句:

    import java.sql.Connection;

    import java.sql.DriverManager;

    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 DBPASSWORD = "mysqladmin";

    private Connection conn = null;

    public DatabaseConnection() throws Exception{

        try{

                Class.forName(DBDRIVER);

                this.conn = DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD);

             }catch(Exception e){

                 throw e;

              }

         {

     public Connection getConnection(){

       return this conn;

     }

    public void close() throws Exception{

       if (this.conn!=null){

           try{

                  this.conn.close();

               }catch(Exception e){

                  throw e;

            }

         }

       }

    }

  • 相关阅读:
    协程—gevent模块的使用
    协程—概念以及基本使用
    Python—同步和互斥
    Hugo博客搭建
    Linux编辑利器-Vim
    Linux命令与Shell
    python入门基础
    .netcore程序在linux下用supervisor守护
    .netcore中添加Swagger
    winform或wpf中全局异常捕获
  • 原文地址:https://www.cnblogs.com/belingzhong/p/2536323.html
Copyright © 2011-2022 走看看