标签:etc dbus except 取数据 jdb trace gen manager mys
package com.java1234.util; import java.sql.Connection; import java.sql.DriverManager; public class DbUtil { private String dbUrl="jdbc:mysql://localhost:3306/db_studentInfo?characterEncoding=utf8"; private String dbUserName="root"; private String dbPassword="root"; private String jdbcName="com.mysql.jdbc.Driver"; /** * 获取数据库连接 * @return * @throws Exception */ public Connection getCon() throws Exception{ Class.forName(jdbcName); Connection con=DriverManager.getConnection(dbUrl,dbUserName,dbPassword); return con; } /** * 关闭数据库连接 * @param con * @throws Exception */ public void closeCon(Connection con) throws Exception{ if(con!=null){ con.close(); } } public static void main(String[] args) { DbUtil dbUtil=new DbUtil(); try { dbUtil.getCon(); System.out.println("数据库连接成功"); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
标签:etc dbus except 取数据 jdb trace gen manager mys
原文地址:https://www.cnblogs.com/qiwb/p/14738824.html