Hi, I have a question regarding Resultsets in JSP.
I have a HTML form that gives 2 variables from textfields to another JSP page, which adds it to the database using the given variables in a query. Now i want the form to also include the messagenumber (this number is the primary key of the table messages). In the page I use a SQL statement (String query = "SELECT count(messageNr) FROM messages"; )to get the number of rows. In the receiving JSP page i then determine the new messageNumber by getting the value of the SQL statement and adding 1 to it.
The problem is that all of the elements work fine on their own. But when I use the Resultset to fill the HTML form it suddenly returns NULL. Here is the full source code and the error I get:
SOURCE:
<%@ page language="java" contentType="text/html" import="java.sql.*" %>
<html>
<head>
<title>** Add message **</title>
</head>
<body>
<body bgcolor="#000000" text="#FF0000" link="#FFFF00" vlink="#FFFF00" alink="#FFFF00">
<%
Class.forName("com.mysql.jdbc.Driver"
Connection myConn=DriverManager.getConnection("jdbc:mysql://localhost/test?user=root&password=root"
Statement stmt = myConn.createStatement();
String query = "SELECT count(messageNr) FROM messages";
ResultSet resultaat = stmt.executeQuery( query );
while(resultaat.next())
{
String Countresultaat = resultaat.getString("count(messageNr)"
}
%>
<form name="formAddMessage" method="post" action="addMessageOut.jsp">
<CENTER>TITEL:<BR>
<input type="text" name="inputMessageKop" size="40" maxlength="60">
<BR>
<BR>BERICHT:<BR>
<textarea name="inputMessageBody" cols="50" rows="20"></textarea>
<BR>
<input type="hidden" name="Begin" value = "<%= CountResultaat %>">
<input type="submit" name="Submit" value="Post Message">
<BR>
</form>
</body>
</html>
ERROR:
cannot resolve symbol variable CountResultaat
This refers to the "<input type="hidden" name="Begin" value = "<%= CountResultaat %>"> " part.
Can anyone please help me?
Thanks in advance!
Menno.
I have a HTML form that gives 2 variables from textfields to another JSP page, which adds it to the database using the given variables in a query. Now i want the form to also include the messagenumber (this number is the primary key of the table messages). In the page I use a SQL statement (String query = "SELECT count(messageNr) FROM messages"; )to get the number of rows. In the receiving JSP page i then determine the new messageNumber by getting the value of the SQL statement and adding 1 to it.
The problem is that all of the elements work fine on their own. But when I use the Resultset to fill the HTML form it suddenly returns NULL. Here is the full source code and the error I get:
SOURCE:
<%@ page language="java" contentType="text/html" import="java.sql.*" %>
<html>
<head>
<title>** Add message **</title>
</head>
<body>
<body bgcolor="#000000" text="#FF0000" link="#FFFF00" vlink="#FFFF00" alink="#FFFF00">
<%
Class.forName("com.mysql.jdbc.Driver"
Connection myConn=DriverManager.getConnection("jdbc:mysql://localhost/test?user=root&password=root"
Statement stmt = myConn.createStatement();
String query = "SELECT count(messageNr) FROM messages";
ResultSet resultaat = stmt.executeQuery( query );
while(resultaat.next())
{
String Countresultaat = resultaat.getString("count(messageNr)"
}
%>
<form name="formAddMessage" method="post" action="addMessageOut.jsp">
<CENTER>TITEL:<BR>
<input type="text" name="inputMessageKop" size="40" maxlength="60">
<BR>
<BR>BERICHT:<BR>
<textarea name="inputMessageBody" cols="50" rows="20"></textarea>
<BR>
<input type="hidden" name="Begin" value = "<%= CountResultaat %>">
<input type="submit" name="Submit" value="Post Message">
<BR>
</form>
</body>
</html>
ERROR:
cannot resolve symbol variable CountResultaat
This refers to the "<input type="hidden" name="Begin" value = "<%= CountResultaat %>"> " part.
Can anyone please help me?
Thanks in advance!
Menno.