您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

数据库链接_MySQL

2024/3/28 18:38:09发布21次查看
数据库链接_mysql
import java.sql.connection; import java.sql.drivermanager; import java.sql.preparedstatement; import java.sql.resultset; import java.sql.sqlexception; public class dbutils { private static final string url="jdbc:mysql://localhost:3306/jdbc?characterencoding=utf-8"; private static final string uer_name = "root"; private static final string pdw="123123"; private static dbutils me = new dbutils(); public static dbutils getinstance(){ return me; } //为了是单例模式成为唯一可以获取该对象的方法,将该类的无参构造函数设为私有 private dbutils(){} /* * 数据库连接 */ public connection getconn(){ connection conn = null; try { class.forname("com.mysql.jdbc.driver"); conn = drivermanager.getconnection(url, uer_name,pdw); } catch (classnotfoundexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (sqlexception e) { // todo auto-generated catch block e.printstacktrace(); } return conn; } /* * 释放资源 */ public void releaseres(connection conn,preparedstatement pstmt,resultset rs){ try { if(conn!=null) conn.close(); if(pstmt!=null) pstmt.close(); if(rs!=null) rs.close(); } catch (sqlexception e) { // todo auto-generated catch block e.printstacktrace(); } } }
以上就是数据库链接_mysql的内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product