package top.yeaho.sql.postgresql;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class Demo01 {
	public static void main(String args[]) {
		Connection c = null;
		Statement stmt = null;
		try {
			Class.forName("org.postgresql.Driver");
			//c = DriverManager.getConnection("jdbc:postgresql://localhost:5432/test", "postgres", "root");
			c = DriverManager.getConnection("jdbc:postgresql://114.115.203.28:5432/best", "postgres", "postgresADMIN");
			c.setAutoCommit(false); // 把自动提交
			System.out.println("远程数据库连接成功，Opened database successfully");

			stmt = c.createStatement(); 
	        /*String sql = "CREATE TABLE STUDENTS " + 
	                     "(ID TEXT PRIMARY KEY     NOT NULL ," + 
	                     " NAME            TEXT    NOT NULL, " + 
	                     " SEX             TEXT    NOT NULL, " + 
	                     " AGE             TEXT    NOT NULL)"; */
			String createTable = "CREATE TABLE information "+ 
                    "(id SERIAL PRIMARY KEY NOT NULL ," + 
                    " info JSONB NOT NULL)" ;
			System.out.println(createTable);
			//String sql = "INSERT INTO information (info) VALUES ( '{\"age\":20,\"name\":\"jeff\"}')";
			String sql = "INSERT INTO information (info) VALUES ( '{\"age\":19,\"name\":\"apple\"}')";
	        //stmt.executeUpdate(createTable);
	        //System.out.println("创建数据库成功，successfully");
			//stmt.executeUpdate(sql); 
	        System.out.println("插入记录成功，successfully");
	        ResultSet rSet = stmt.executeQuery("select '[{\"a\":\"foo\"},{\"b\":\"bar\"},{\"c\":\"baz\"}]'::json->2");
	        if(rSet.next()){
	        	System.out.println("has next!");
	        	System.out.println(rSet.getString(1));
	        	/*测试github*/
			/*这也是测试*/
	        	
	        }
			stmt.close();
			c.commit();
			c.close();
		} catch (Exception e) {
			System.err.println(e.getClass().getName() + ": " + e.getMessage());
			System.exit(0);
		}
	}
}

@@ -549,13 +549,10 @@
  // 
-%E6%8A%8A%E8%87%AA%E5%8A%A8%E6%8F%90%E4%BA%A4
+%D4%B6%E1%BD%BB
 %0A%09%09%09
@@ -575,18 +575,12 @@
 ln(%22
-%E8%BF%9C%E7%A8%8B%E6%95%B0%E6%8D%AE%E5%BA%93%E8%BF%9E%E6%8E%A5%E6%88%90%E5%8A%9F%EF%BC%8C
+%D4%B6%DD%BF%D3%B3%C9%B9
 Open
@@ -1407,16 +1407,10 @@
 ln(%22
-%E5%88%9B%E5%BB%BA%E6%95%B0%E6%8D%AE%E5%BA%93%E6%88%90%E5%8A%9F%EF%BC%8C
+%DD%BF%C9%B9
 succ
@@ -1485,15 +1485,10 @@
 ln(%22
-%E6%8F%92%E5%85%A5%E8%AE%B0%E5%BD%95%E6%88%90%E5%8A%9F%EF%BC%8C
+%C2%BC%C9%B9
 succ
@@ -1745,18 +1745,16 @@
      %09/*
-%E6%B5%8B%E8%AF%95
 github*/
@@ -1758,21 +1758,8 @@
 b*/%0A
-%09%09%09/*%E8%BF%99%E4%B9%9F%E6%98%AF%E6%B5%8B%E8%AF%95*/%0A
 %09   
@@ -1945,10 +1945,9 @@
 %0A%09%09%7D%0A%09%7D%0A
+
 %7D
-%0A

Revert "test"