📄 initdatabase.java
字号:
/* * 作者: 胡李青 * qq: 31703299 * Copyright (c) 2007 huliqing * 主页 http://www.tbuy.biz/ * 你可以免费使用该软件,未经许可请勿作用于任何商业目的,如有技术问题请与本人联系! * * 本来想用这个类帮助简化mysql数据库的创建,但因时间问题,暂未处理. */package biz.tbuy.common;import java.sql.Connection;import java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql.SQLException;import java.sql.Statement;import java.util.logging.Level;import java.util.logging.Logger;/** * @deprecated 暂时无用 * @author huliqing * <p><b>qq:</b>31703299 * <p><b>E-mail:</b><a href="mailto:huliqing.cn@gmail.com">huliqing.cn@gmail.com</a> * <p><b>Homepage:</b><a href="http://www.tbuy.biz/">http://www.tbuy.biz/</a> */public class InitDatabase { private String driver; private String url; private String user; private String password; private Connection conn; private Statement state; private PreparedStatement ps; public InitDatabase(String driver, String url, String user, String password) { this.driver = driver; this.url = url; this.user = user; this.password = password; this.connection(); } public Connection getConn() { return conn; } public void connection() { // System.out.println("connection start..."); try { Class.forName(driver); } catch (Exception e) { System.out.println("can't load driver"); } try { conn = DriverManager.getConnection(url, user, password); } catch (Exception e) { System.out.println("can't open database"); } // System.out.println("connection success"); } /** * @return Statement */ public Statement createStatement() { try { state = conn.createStatement(); } catch (SQLException sqle) { System.out.println("Statement" + sqle.getMessage()); } return state; } /** * PreparedStatement * @param sql * @return PreparedStatement */ public PreparedStatement PrepareStatement(String sql) { try { ps = conn.prepareStatement(sql); } catch (SQLException sqle) { System.out.println("Error:" + sqle.getMessage()); } return ps; } /** * */ public void close() { if (conn != null) { try { conn.close(); } catch (SQLException ex) { Logger.getLogger("global").log(Level.SEVERE, null, ex); } } if (state != null) { try { state.close(); } catch (SQLException ex) { Logger.getLogger("global").log(Level.SEVERE, null, ex); } } if (ps != null) { try { ps.close(); } catch (SQLException ex) { Logger.getLogger("global").log(Level.SEVERE, null, ex); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -