1 11 package com.nilostep.xlsql.sql; 12 13 import java.text.*; 14 15 18 public abstract class xlSqlWriter { 19 26 abstract public String wCreateSchema(String schema); 27 28 38 public String wCreateTable(String s, 39 String t, 40 String [] co, 41 String [] ty) { 42 String sql; 43 sql = "CREATE TABLE " + getTableName(s, t) + " ( "; 44 45 boolean firstcolumn = true; 46 47 for (int i = 0; i < co.length; i++) { 48 if (firstcolumn) { 49 firstcolumn = false; 50 } else { 51 sql = sql + ","; 52 } 53 54 sql = sql + co[i] + " " + ty[i]; 55 } 56 57 sql = sql + " );"; 58 59 return sql; 60 } 61 62 70 abstract public String wDropTable(String schema, 71 String table); 72 73 84 public String wInsert(String s, 85 String t, 86 String [] co, 87 String [] ty, 88 String [] va) { 89 String sql; 90 sql = "INSERT INTO " + getTableName(s, t) + " VALUES ("; 91 92 boolean firstcolumn = true; 93 94 for (int i = 0; i < co.length; i++) { 95 if (firstcolumn) { 96 firstcolumn = false; 97 } else { 98 sql = sql + ","; 99 } 100 101 if (va[i] == null) { 102 sql = sql + "null"; 103 104 continue; 105 } 106 107 if (va[i].equals("")) { 108 sql = sql + "null"; 109 110 continue; 111 } 112 113 if ("DOUBLE".equals(ty[i]) || "BIT".equals(ty[i])) { 114 sql = sql + va[i]; 115 } else if ("DATE".equals(ty[i])) { 116 try { 117 SimpleDateFormat dateFormat = 118 new SimpleDateFormat("dd/MM/yyyy"); 119 java.util.Date d; 120 d = dateFormat.parse(va[i]); 121 dateFormat.applyPattern("yyyy-MM-dd"); 122 sql = sql + "'" + dateFormat.format(d) + "'"; 123 } catch (ParseException pe) { 124 sql = sql + "null"; 125 } 126 } else { 127 sql = sql + "'" + va[i] + "'"; 128 } 129 } 130 131 sql = sql + " );"; 132 133 return sql; 134 } 135 136 abstract protected String getTableName(String schema, 137 String table); 138 } | Popular Tags |