Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- public class pSQL {
- //LP version
- public final static String MYSQL_HOST = "127.0.0.1";
- public final static String MYSQL_DBNAME = "bili";
- public final static String MYSQL_USER = "root";
- public final static String MYSQL_PASS = "NyaNya";
- static {
- try {
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- } catch (Exception e) {
- e.printStackTrace(System.out);
- }
- }
- public ResultSet rset;
- public String errmsg = "none.";
- public PreparedStatement ps;
- private Connection ction;
- private Statement statement;
- private ResultSetMetaData rsmd;
- public boolean connect(String Host, String dbName, String User, String Pass) throws SQLException {
- String url = "jdbc:mysql://" + Host + "/" + dbName + "?user=" + User + "&password=" + Pass + "&useUnicode=true&characterEncoding=utf8";//ָ������ ���PreparedStatement����
- ction = DriverManager.getConnection(url);
- statement = ction.createStatement();
- return ction != null && statement != null;
- }
- public boolean connect() throws SQLException {
- return connect(MYSQL_HOST, MYSQL_DBNAME, MYSQL_USER, MYSQL_PASS);
- }
- public PreparedStatement pre(String sql) throws SQLException {
- if (ction == null) this.connect();
- ps = ction.prepareStatement(sql);
- return ps;
- }
- public PreparedStatement pre() {
- return ps;
- }
- public int exec() throws SQLException {
- return ps.executeUpdate();
- }
- public ResultSet query() throws SQLException {
- rset = ps.executeQuery();
- rsmd = rset.getMetaData();
- return rset;
- }
- public ResultSet rset() {
- return rset;
- }
- public boolean exec(String line) throws SQLException {
- return statement.execute(line);
- }
- public ResultSet query(String line) throws SQLException {
- rset = statement.executeQuery(line);
- rsmd = rset.getMetaData();
- return rset;
- }
- public int tcount() {
- if (rsmd == null) return -1;
- try {
- return rsmd.getColumnCount();
- } catch (Exception e) {
- return -2;
- }
- }
- public int count() throws SQLException {
- int cou = 0;
- while (rset.next()) {
- cou++;
- }
- return cou;
- }
- public boolean isconnected() {
- return !(ction == null);
- }
- public void close() {
- try {
- ction = null;
- rset.close();
- statement.close();
- ction.close();
- } catch (Exception e) {
- //e.printStackTrace(System.out);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement