Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ro.scoalainformala.helper;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.Properties;
- public class DBHelper {
- public static Connection getConnection() {
- Properties connectionProperties = new Properties();
- connectionProperties.put("user", "root");
- connectionProperties.put("password", "She is going places1");
- String connString = "jdbc:mysql://localhost:3306/bank_curs";
- try {
- Connection conn = DriverManager.getConnection(connString, connectionProperties);
- conn.setAutoCommit(false);
- Statement stmt = conn.createStatement();
- ResultSet rs = stmt.executeQuery("select * from bank");
- while (rs.next()) {
- int id = rs.getInt("id");
- String name = rs.getString("name");
- String countryCode = rs.getString("country_code");
- System.out.println(id + " " + name + " " + countryCode);
- }
- conn.close();
- } catch (SQLException e) {
- e.printStackTrace();
- return null;
- }
- }
- public static void closeConnection(Connection conn) {
- try {
- conn.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement