Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- public class DB {
- public Connection conn = null;
- public DB() {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- String url = "jdbc:mysql://localhost:3306/landme";
- conn = DriverManager.getConnection(url, "root", "");
- System.out.println("conn built");
- } catch (SQLException e) {
- e.printStackTrace();
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- }
- }
- public ResultSet runSql(String sql) throws SQLException {
- Statement sta = conn.createStatement();
- return sta.executeQuery(sql);
- }
- public boolean runSql2(String sql) throws SQLException {
- Statement sta = conn.createStatement();
- return sta.execute(sql);
- }
- @Override
- protected void finalize() throws Throwable {
- if (conn != null || !conn.isClosed()) {
- conn.close();
- }
- }
- }
Add Comment
Please, Sign In to add comment