I am interested in getting out the value from the DATABASE and get it into textbox value property, here is my code:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import="java.sql.*" %>
<!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=ISO-8859-1">
<title>Update Your Data</title>
</head>
<body>
<%! ResultSet rs; %>
<%! Connection con;%>
<%! PreparedStatement pstmt;%>
<%! String sql = "SELECT * FROM USERS WHERE USERNAME = ?"; %>
**<%! String unm,pwd; %>**
<h3>Update Your Details</h3>
<hr/>
<form action="UpdateSrvlt" method="post">
<%
try{
Class.forName("com.mysql.jdbc.Driver");
}catch(ClassNotFoundException cnfe){
System.out.println("Error :"+cnfe.getMessage());
}
try{
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","");
pstmt = con.prepareStatement(sql);
pstmt.setString(1,request.getParameter("username"));
rs = pstmt.executeQuery();
while(rs.next()){
**unm = rs.getString("username");**
System.out.println("Username at Update.jsp: "+unm);
**pwd = rs.getString("password");**
System.out.println("Password at Update.jsp: "+pwd);
}
}catch(SQLException se){
System.out.println("Error :"+ se.getMessage());
}
%>
<table>
<tr>
<td align="left">
Username :
</td>
<td align="left">
<input type="text" name="username" value="${unm}"/>
</td>
</tr>
<tr>
<td align="left">
Password :
</td>
<td>
<input type="text" name="password" value="${pwd}" />
</td>
</tr>
<tr>
<td><input type="submit" value="Update" /></td>
</tr>
<%
pstmt.close();
con.close();
%>
</table>
</form>
</body>
</html>
Anybody know the reason what is the reason for getting null..inspite of getting variable value.