日期:2014-05-17 浏览次数:20611 次
package com.henu.util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class DbConnection
{
private static final String DRIVER = "com.mysql.jdbc.Driver";//什么意思,是指路径还是?
private static final String URL = "jdbc:mysql://localhost:3306/zcbtext";
private static final String USER = "root";//mysql用户名
private static final String PASSWORD = "password";
public static synchronized Connection getConn()
{
Connection conn = null;
try
{
Class.forName(DRIVER);
conn = DriverManager.getConnection(URL, USER, PASSWORD);
}
catch (Exception e)
{
e.printStackTrace();
}
return conn;
}
public static synchronized void closeAll(ResultSet rs, Statement st,
Connection conn)
{
if (rs != null)
{
try
{
rs.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
if (st != null)
{
try
{
st.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
if (conn != null)
{
try
{
conn.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
}