1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- package com.sinosoft.lz.he.quiTools;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.ArrayList;
- public class BmRelationCon {
- static Connection conn = getConnection();
-
- public static void main(String[] args) {
- String sql = "select COLUMN_NAME from user_tab_columns where Table_Name='EM_SECOND_REPORT'";
- ResultSet rs = null;
- Statement st = null;
-
- ArrayList<String> list = new ArrayList<String>();
-
- try {
- st = conn.createStatement();
- rs = st.executeQuery(sql);
- while (rs.next()) {
- String columnName = rs.getString("COLUMN_NAME");
-
- if(!columnName.equals("FD_OBJECTID")&&
- !columnName.equals("EVENT_ID")&&
- !columnName.equals("IS_DEL")&&
- !columnName.equals("UPDATEDATE")&&
- !columnName.equals("REMARK")&&
- !columnName.equals("PERSONNEL")&&
- !columnName.equals("FILL_TIME")
- ){
- list.add(columnName);
- }
- }
- StringBuffer sb = new StringBuffer();
- for (int i = 0; i < list.size(); i++) {
- sb.append("insert into BM$_MAPVALUECANST (FD_CODE,FD_DESCRIPTION,FD_TYPE,FD_SORT) VALUES (");
- sb.append("'"+(i+1)+"',"+"'"+list.get(i)+"','BM$_RELATION_CONDITION',"+(i+1)+");\n");
- }
-
- System.out.println(sb.toString());
-
-
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- close();
- }
-
-
-
- }
- public static void close(){
- try {
- if (conn!=null) {
- conn.close();
- System.out.println("关闭数据库链接---");
- }
- } catch (Exception e) {
- System.out.println(e.toString());
- }
- }
-
- public static Connection getConnection() {
- Connection conn = null;
- String url = "jdbc:oracle:thin:@192.168.1.118:1521:ORCL";
- String username = "JXLW";
- String password = "JXLW";
- String className = "oracle.jdbc.driver.OracleDriver";
- try {
- Class.forName(className);
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- }
- try {
- conn = DriverManager.getConnection(url, username, password);
- System.out.println("数据库连接建立成功...");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return conn;
- }
- }
|