Assign value to HTML textbox from JSP
- by prakash_d22
Hello I am creating a web page to add some information about given product.I need to enter id,name,description and image as information.I need the id to be auto generated.I am using jsp and database as access.I am fetching the count(*)+1 value from database and assigning to my html text box but its showing as null.can i get some help?
Code:
<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