postgresql 入門(含java、scala串連代碼)

來源:互聯網
上載者:User

標籤:

1、下載安裝包

官網:http://www.postgresql.org/download/ 按自己需求,下載安裝包,

我下載的windows版32位的。http://get.enterprisedb.com/postgresql/postgresql-9.4.0-1-windows.exe

2、安裝

執行下載包,進行安裝,請一定記住你輸入的密碼,如“pg”

3、開啟資料庫,建立表,插入資料

安裝完成後,在開始菜單找到PostgreSQL 9.4 (x86)\pgAdmin III,開啟 pgAdmin III,點擊節點,輸入密碼“pg”

串連後

點擊 ,在新開啟的視窗輸入下邊語句,建立表,插入資料

CREATE TABLE users (     uid    serial PRIMARY KEY ,     name   varchar(40) NOT NULL CHECK (name <> ‘‘),     pwd varchar(40) NOT NULL CHECK (name <> ‘‘),     gender char(1),     email varchar(40),     birthday date     );INSERT INTO users VALUES  (1, ‘zxh‘, ‘zxhpwd‘, ‘M‘, ‘[email protected]‘, ‘1984-07-13‘);  INSERT INTO users VALUES  (2, ‘zxh2‘, ‘zxh2pwd‘, ‘F‘, ‘[email protected]‘, ‘1984-07-13‘);

展開分類樹, 選中表“users”,點“”查看資料

4、下載驅動

在開啟也找到

開啟psqljdbc,--“download”--然後找到下面

5、java連結postgresql
//psqlJDBC //Publisher :PostgreSQL Global Development Group//驅動地址:http://jdbc.postgresql.org/download.html => http://jdbc.postgresql.org/download/postgresql-9.3-1102.jdbc41.jar//本地下載:http://files.cnblogs.com/piaolingzxh/postgresql-9.3-1102.jdbc41.jar.zipimport java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.ResultSetMetaData;import java.sql.Statement;public class postgres_jdbc {public static void main(String[] args) {try {Class.forName("org.postgresql.Driver").newInstance();String url = "jdbc:postgresql://localhost:5432/postgres";Connection con = DriverManager.getConnection(url, "postgres", "pg");Statement st = con.createStatement();String sql = " select * from users ";ResultSet rs = st.executeQuery(sql);ResultSetMetaData rsmd = rs.getMetaData();int columnCount = rsmd.getColumnCount();while (rs.next()) {for (int i = 1; i <= columnCount; i++) {System.out.print(rs.getString(i)+"\t");}System.out.println();}rs.close();st.close();con.close();} catch (Exception ee) {System.out.print(ee.getMessage());}}}
6、scala串連資料庫
//psqlJDBC //Publisher : PostgreSQL Global Development Group//驅動地址:http://jdbc.postgresql.org/download.html => http://jdbc.postgresql.org/download/postgresql-9.3-1102.jdbc41.jar//本地下載:http://files.cnblogs.com/piaolingzxh/postgresql-9.3-1102.jdbc41.jar.zipimport java.sql.{ Connection, DriverManager, ResultSet };object postgres_jdbc {  val conn_str = "jdbc:postgresql://localhost:5432/postgres"  classOf[org.postgresql.Driver]  def main(args: Array[String]) {    //classOf[org.postgresql.Driver]    val conn = DriverManager.getConnection(conn_str, "postgres", "pg")    try {      // Configure to be Read Only      val statement = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY)      // Execute Query      val rs = statement.executeQuery("SELECT * FROM users")      var columnCount = rs.getMetaData().getColumnCount();      // Iterate Over ResultSet      while (rs.next) {        for (i <- 1 to columnCount) {          System.out.print(rs.getString(i) + "\t");        }        System.out.println();      }    } finally {      conn.close    }  }}
7、PostgreSQL 8.1 中文文檔

http://www.php100.com/manual/PostgreSQL8/

 

postgresql 入門(含java、scala串連代碼)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.