Java JDBC PostgreSQL Connection getDataFromTable(String tableName, String[] columns)

Here you can find the source of getDataFromTable(String tableName, String[] columns)

Description

get Data From Table

License

Open Source License

Declaration

public static LinkedList<String> getDataFromTable(String tableName, String[] columns) 

Method Source Code


//package com.java2s;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.LinkedList;

public class Main {
    public static LinkedList<String> getDataFromTable(String tableName, String[] columns) {
        Connection conn = getConnection();
        LinkedList<String> list = new LinkedList<String>();
        try {/*from   w  w w.j  a v  a2 s.c o m*/
            Statement st = conn.createStatement();
            String sb = "select * from " + tableName;
            ResultSet rs = st.executeQuery(sb);
            while (rs.next()) {
                StringBuilder sql = new StringBuilder();
                sql.append(
                        "INSERT INTO leo_primitive_type (leo_uuid, leo_database_type, leo_ruby_type,leo_java_type,leo_identifier) VALUES ('");
                sql.append(rs.getString("io_uuid")).append("','").append(rs.getString("io_database_type"))
                        .append("','").append(rs.getString("io_ruby_type")).append(rs.getString("io_java_type"))
                        .append("','").append(rs.getString("io_identifier")).append("','").append("');");
                list.add(sql.toString());
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return list;
    }

    private static Connection getConnection() {
        Connection con = null;
        try {
            Class.forName("org.postgresql.Driver");
            String url = " jdbc:postgresql://localhost:5432/intalio";
            con = DriverManager.getConnection(url, "postgres", "root");
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return con;
    }
}

Related

  1. ClearDatabase()
  2. createConnection()
  3. getConnection()
  4. getConnection()
  5. getDBConnection()
  6. getListDatabaseFromMaster()
  7. getPostgresConnection()
  8. getPostgresConnection()