您可能需要爲某種形式的建設者,其建立在飛的形式,可以採取幫助代碼從下面的代碼創建動態SQL表。這僅僅是一個暗示不是你的問題的完美解決方案
嘗試{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbctest", "root", "123");
Statement st = con.createStatement();
System.out.println("connection has been made ");
Scanner scanner = new Scanner(System.in);
System.out.println("please enter table name ");
String tableName = scanner.next();
String strr = null;
System.out.println("Enter no of columns you like to use: ");
int noc = scanner.nextInt();
for (int i = 1; i <= noc; i++) {
BufferedReader bf = new BufferedReader(new InputStreamReader(
System.in));
System.out.println("Enter column name with type ");
String s1 = bf.readLine();
if (strr == null) {
strr = s1;
} else {
strr = strr + s1;
}
}
st.executeUpdate("create table " + tableName + "(" + strr + ")");
System.out.println("your table " + tableName
+ " has been created!!!");
ResultSet rs = st.executeQuery("SELECT * FROM " + tableName);
ResultSetMetaData rsmd = rs.getMetaData();
int NumOfCol = rsmd.getColumnCount();
System.out.println("Number of Columns of your table =" + tableName
+ " " + NumOfCol);
System.out.println("Column names are ");
for (int i = 1; i <= NumOfCol; i++) {
System.out.println(rsmd.getColumnName(i));
}
String strn = null;
System.out.println("please enter values you need to insert");
for (int i = 1; i <= NumOfCol; i++) {
String s5 = scanner.next();
if (strn == null) {
strn = s5;
} else
strn = strn + s5;
}
System.out.println(strn);
st.executeUpdate("insert into " + tableName + " values" + "("
+ strn + ")");
System.out.println("your table " + tableName
+ " has been filled!!!");
con.close();
System.out.println("connection has been colsed ");
}
catch (Exception e) {
System.out.println(e.getMessage());
}
在這裏,在我的問題,db表山坳的是根據正在由用戶設計的表格類型生成。他只是拖放HTML組件來創建設計。 – Anish
我得到了你的觀點,這就是爲什麼我建議你尋找某種表單生成器工具,它可以動態創建HTML Web表單並將從這些動態Web表單發佈的值存儲到數據庫中。您可能會發現以下鏈接有用https://code.google.com/p/jquery-form-builder-plugin/ – Pawan