日期:2014-05-18  浏览次数:20777 次

急,急,急,急,急,急,急!!!!如何根据数据库建立相应的表单???????????小弟我搞了好多天了,还是没有搞定.....
急,急,急,急,急,急,急!!!!如何根据数据库建立相应的表单???????????小弟我搞了好多天了,还是没有搞定.....

先谢谢各位了哈!!!!!!!!!!!!

------解决方案--------------------
在界面生成表单?

try {
// Create a result set
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery( "SELECT * FROM my_table where rownum <=1 ");

// Get result set meta data
ResultSetMetaData rsmd = rs.getMetaData();
int numColumns = rsmd.getColumnCount();

// Get the column names; column indices start from 1
for (int i=1; i <numColumns+1; i++) {
String columnName = rsmd.getColumnName(i);

// Get the name of the column 's table name
String tableName = rsmd.getTableName(i);

out.println( " <input type= 'text ' name= ' "+tableName+ " ' />
}
} catch (SQLException e) {
}


------解决方案--------------------
orm先生成javaBean,作为Form,根据该Form生成表单
------解决方案--------------------
<%@ page contentType= "text/html; charset=gb2312 " language= "java " import= "java.sql.*,oracle.jdbc.driver.* " errorPage= " " %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN " "http://www.w3.org/TR/html4/loose.dtd ">
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<title> 无标题文档 </title>
</head>

<body>
<table>
<tr>
<td> 姓名 </td>
<td> 年龄 </td>
<td> 性别 </td>
</tr>
<%
DriverManager.registerDriver(new OracleDriver());
/*******下面程序中1521为oralce默认端口,www为oracle的SID,后面test为用户名和密码****************/
Connection conn = DriverManager.getConnection( "jdbc:oracle:thin:@localhost:1521:myoracle ", "test ", "sa ");

Statement stmt_com=conn.createStatement();
//stmt_com.executeUpdate( "insert into TEST_STUDENT(id,name` ,age,sex) values( '1003 ', '小王 ', '29 ', '女 ') ");
//stmt_com.executeUpdate( "update test_student set name= '小刘 ',sex= '男 ' where name= '小王 ' ");
ResultSet rs_com=stmt_com.executeQuery( "select * from STUDENT ");
while(rs_com.next())
{
%>
<tr>
<td> <%=rs_com.getString( "name ")%> </td>
<td> <%=rs_com.getString( "age ")%> </td>
<td> <%=rs_com.getString( "sex ")%> </td>
</tr>
<%
}
rs_com.close();
stmt_com.close();
conn.close();
%>
</table>

</body>
</html>
这是我的,可以参考下。
------解决方案--------------------
要和hibernate类似的效果么???
------解决方案--------------------
这样是不行的,生成了表单文本筐,还有描述类,排版呢,怎么获取值提交表单返回值呢,多着呢,学着吧,告诉你用xml+xsl可以实现