java方法

来源:互联网 发布:虎牙 斗鱼 知乎 编辑:程序博客网 时间:2024/04/30 01:17

  String sql = "select * from " + tablename;

  PreparedStatement pStemt = null;

  try {

  try {

  Class.forName(DRIVER);

  } catch (ClassNotFoundException e1) {

  e1.printStackTrace();

  }

  con = DriverManager.getConnection(URL,NAME,PASS);

  pStemt = con.prepareStatement(sql);

  ResultSetMetaData rsmd = pStemt.getMetaData();

  int size = rsmd.getColumnCount(); //统计列

  colnames = new String[size];

  colTypes = new String[size];

  colSizes = new int[size];

  for (int i = 0; i < size; i++) {

  colnames[i] = rsmd.getColumnName(i + 1);

  colTypes[i] = rsmd.getColumnTypeName(i + 1);

  if(colTypes[i].equalsIgnoreCase("datetime")){

  f_util = true;

  }

  if(colTypes[i].equalsIgnoreCase("image") || colTypes[i].equalsIgnoreCase("text")){

  f_sql = true;

  }

  colSizes[i] = rsmd.getColumnDisplaySize(i + 1);

  }

  String content = parse(colnames,colTypes,colSizes);

  try {

  File directory = new File("");

  String outputPath = directory.getAbsolutePath()+ "/src/"+this.packageOutPath.replace(".", "/")+"/"+initcap(tablename) + ".java";

  FileWriter fw = new FileWriter(outputPath);

  PrintWriter pw = new PrintWriter(fw);

  pw.println(content);

  pw.flush();

  pw.close();

  } catch (IOException e) {

  e.printStackTrace();

  }

  } catch (SQLException e) {

  e.printStackTrace();

  } finally{

  // try {

  // con.close();

  // } catch (SQLException e) {

  // // TODO Auto-generated catch block

  // e.printStackTrace();

  // }

  }

  }

  System.out.println("生成完毕!");

  }

  /**

0 0
原创粉丝点击