2812d12392427d870420fe9a1be776267734865c.svn-base 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package com.sinosoft.lz.he.quiTools;
  2. import java.sql.Connection;
  3. import java.sql.DriverManager;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. import java.sql.Statement;
  7. import java.util.ArrayList;
  8. public class BmRelationCon {
  9. static Connection conn = getConnection();
  10. public static void main(String[] args) {
  11. String sql = "select COLUMN_NAME from user_tab_columns where Table_Name='EM_SECOND_REPORT'";
  12. ResultSet rs = null;
  13. Statement st = null;
  14. ArrayList<String> list = new ArrayList<String>();
  15. try {
  16. st = conn.createStatement();
  17. rs = st.executeQuery(sql);
  18. while (rs.next()) {
  19. String columnName = rs.getString("COLUMN_NAME");
  20. if(!columnName.equals("FD_OBJECTID")&&
  21. !columnName.equals("EVENT_ID")&&
  22. !columnName.equals("IS_DEL")&&
  23. !columnName.equals("UPDATEDATE")&&
  24. !columnName.equals("REMARK")&&
  25. !columnName.equals("PERSONNEL")&&
  26. !columnName.equals("FILL_TIME")
  27. ){
  28. list.add(columnName);
  29. }
  30. }
  31. StringBuffer sb = new StringBuffer();
  32. for (int i = 0; i < list.size(); i++) {
  33. sb.append("insert into BM$_MAPVALUECANST (FD_CODE,FD_DESCRIPTION,FD_TYPE,FD_SORT) VALUES (");
  34. sb.append("'"+(i+1)+"',"+"'"+list.get(i)+"','BM$_RELATION_CONDITION',"+(i+1)+");\n");
  35. }
  36. System.out.println(sb.toString());
  37. } catch (Exception e) {
  38. e.printStackTrace();
  39. } finally {
  40. close();
  41. }
  42. }
  43. public static void close(){
  44. try {
  45. if (conn!=null) {
  46. conn.close();
  47. System.out.println("关闭数据库链接---");
  48. }
  49. } catch (Exception e) {
  50. System.out.println(e.toString());
  51. }
  52. }
  53. public static Connection getConnection() {
  54. Connection conn = null;
  55. String url = "jdbc:oracle:thin:@192.168.1.118:1521:ORCL";
  56. String username = "JXLW";
  57. String password = "JXLW";
  58. String className = "oracle.jdbc.driver.OracleDriver";
  59. try {
  60. Class.forName(className);
  61. } catch (ClassNotFoundException e) {
  62. e.printStackTrace();
  63. }
  64. try {
  65. conn = DriverManager.getConnection(url, username, password);
  66. System.out.println("数据库连接建立成功...");
  67. } catch (SQLException e) {
  68. e.printStackTrace();
  69. }
  70. return conn;
  71. }
  72. }