package com.chenyang.nse.bussiness.test;

import java.io.UnsupportedEncodingException;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;

public class Oracletest {
   public static void main(String[] args) throws ClassNotFoundException, SQLException, UnsupportedEncodingException {
      String url = "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.2.202)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=ORCL)))";
      String driver = "oracle.jdbc.driver.OracleDriver";
      String passwd = "mydata";
      String user = "mydata";
      Class.forName(driver);
      Connection conn = DriverManager.getConnection(url, passwd, user);
      PreparedStatement ps = null;
      DatabaseMetaData metaData = conn.getMetaData();
      ps = conn.prepareStatement("select * from mydata.table1  a");
      ResultSet tables = metaData.getTables((String)null, (String)null, (String)null, new String[]{"TABLE"});
      System.out.println(metaData);

      while(tables.next()) {
         new HashMap();
         String table_name = tables.getString("TABLE_NAME");
         String table_comment = tables.getString("REMARK");
         if (table_comment != null && !table_comment.isEmpty()) {
            System.out.println(table_comment);
         }
      }

      ps.close();
      conn.close();
   }

   public static void createTable(Connection conn, PreparedStatement ps) throws SQLException {
      for(int i = 0; i < 10; ++i) {
         String sql = "CREATE TABLE YSL.AWQ" + i + "(\tSTUID NUMBER,STUNAME VARCHAR2(10),ACCC VARCHAR2(10),ACAS VARCHAR2(10),ACDF VARCHAR2(10),ACGH VARCHAR2(10),ACJK VARCHAR2(10),ACKL VARCHAR2(10),ACZX VARCHAR2(10),ACCV VARCHAR2(10),STU VARCHAR2(10),STUE VARCHAR2(10), GEQW VARCHAR2(10),GEWE VARCHAR2(10),GEERR VARCHAR2(10),GERT VARCHAR2(10),GENTY VARCHAR2(10),GEYUR VARCHAR2(10),AGE NUMBER(2,0),GE NUMBER(2,0),AE NUMBER(2,0),AE22 NUMBER(2,0),AE34 NUMBER(2,0),AC1 VARCHAR2(10),AC2 VARCHAR2(10),AC3 VARCHAR2(10),AC4 VARCHAR2(10),AC5 VARCHAR2(10),AC6 VARCHAR2(10),AC7 VARCHAR2(10),ST8 VARCHAR2(10),ST9 VARCHAR2(10), GE10 VARCHAR2(10),GE11 VARCHAR2(10),GE12 VARCHAR2(10),GE13 VARCHAR2(10),GE14 VARCHAR2(10),GE15 VARCHAR2(10),AG16 NUMBER(2,0),GE17 NUMBER(2,0),AE18 NUMBER(2,0),JOINDATE DATE,CLASSID NUMBER, ADDRESS VARCHAR2(50)) ";
         ps = conn.prepareStatement(sql);
         ps.execute();
      }

   }
}
