您好,我正在创建一个网页以添加有关给定产品的一些信息。我需要输入 id、名称、描述和图像作为信息。我需要自动生成 id。我使用 jsp 和数据库作为访问。我正在获取数据库中的 count(*)+1 值并分配给我的 html 文本框,但它显示为 null。我能得到一些帮助吗?
代码:
<body>
<%@page import="java.sql.*"%>
<%! String no; %>
<%
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:pd");
ResultSet rs = null;
Statement st = con.createStatement();
String sql = ("select count(*)+1 from products");
st.executeUpdate(sql);
while (rs.next()) {
no=rs.getString("count(*)+1");
}
rs.close();
st.close();
con.close();
}
catch(Exception e){}
%>
<Form name='Form1' action="productcode.jsp" method="post">
<table width="1024" border="0">
<tr>
<td width="10"> </td>
<td width="126">Add Product: </td>
<td width="277"> </td>
<td width="583"> </td>
</tr>
<tr>
<td> </td>
<td>Product Id:</td>
<td><label>
<input type="text" name="id" value="<%= no%>"/>
</label></td>
<td> </td>
.... and so on