Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- /**
- * Created by Dmytro.Sylaiev on 6/15/2017.
- */
- public class Main {
- private static Connection connection;
- private static final String connectionUrl = "";
- private final static String MASTER_USER = "";
- private final static String MASTER_USER_PASSWORD = "";
- public static void main(String[] args) throws Exception {
- java.lang.Class.forName("com.amazon.redshift.jdbc42.Driver");
- connection = DriverManager.getConnection(connectionUrl,MASTER_USER,MASTER_USER_PASSWORD);
- dropTable();
- createTable();
- fillTable(5);
- printTableContent();
- }
- private static void dropTable() throws SQLException {
- PreparedStatement st = connection.prepareStatement("DROP TABLE test_table");
- st.execute();
- }
- private static void createTable() throws SQLException {
- PreparedStatement st1 = connection.prepareStatement("CREATE TABLE IF NOT EXISTS \"public\".\"TEST_table\""
- + "(\"tic_id\" BIGINT NOT NULL identity(1, 1),\"tic_table\" VARCHAR(30) NOT NULL); ");
- st1.execute();
- }
- private static void fillTable(int numberOfRecord) throws SQLException {
- PreparedStatement st3 = connection.prepareStatement("INSERT INTO test_table (tic_table) VALUES (?)");
- for (int i = 0; i < numberOfRecord; i++) {
- st3.setString(1, "test");
- st3.execute();
- }
- }
- private static void printTableContent() throws SQLException{
- PreparedStatement st2 = connection.prepareStatement("SELECT * FROM test_table");
- ResultSet rs = st2.executeQuery();
- while (rs.next()) {
- System.out.println(rs.getInt(1) + " | " + rs.getString(2)) ;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement