import java.sql.Connection;import java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql.SQLException;/** * 文件名称:DBUtils.java * 文件描述: * * 版权声明:(C)2014-2015 * 公司部门:java研发部 * 创建时间:2015年6月1日 * * @author ggf * @version */public class DBUtils { public static final String url = "jdbc:mysql://127.0.0.1/lvyun"; public static final String name = "com.mysql.jdbc.Driver"; public static final String user = "root"; public static final String password = "root"; //开启连接 public static Connection creatConnection(){ Connection conn = null; try { Class.forName(name); conn = DriverManager.getConnection(url, user, password); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return conn; } //执行语句 public PreparedStatement getps(Connection conn,String sql){ PreparedStatement ps = null; try { ps = conn.prepareStatement(sql); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return ps; } //关闭Connection public static void close(Connection conn) { if(conn!=null){ try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } //关闭PreparedStatement public static void close(PreparedStatement ps) { if(ps!=null){ try { ps.close(); } catch (SQLException e) { e.printStackTrace(); } } } }