Display MySQL table data in Text Input boxes.
[nobr]Here I am getting a small Problem in my servlet. This servlet is for Updating
Some records in the table.
first time when servletdoGetinvoked I need to retrive data from the table and pass them to input text boxes. values are getting but partially.
that means if there is value in the table likeABC DEF the servlet will display just only the ABC. what ever the values comes to after the space is not getting. but once i print it out side the text input area entire value comes to the the String variable.
package my.pack;
import java.io.*;
import java.net.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
publicclass hdata_editextends HttpServlet
{
protectedvoid doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
String id=null;
PrintWriter out = response.getWriter();
String hotel_id = request.getParameter("hid").trim();
response.setContentType("text/html");
out.print("<html><body>");
out.print("<code><pre>");
Connection con =null;
Statement stmt =null;
ResultSet rs =null;
try
{
Class.forName("org.gjt.mm.mysql.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost/db?user=root&password=dba");
stmt = con.createStatement();
rs = stmt.executeQuery("SELECT * FROM hotels where hotel_id='"+hotel_id+"'");
out.println("<a href=\"hdata_insert\">Add New Hotel</a>\t<a href=\"hdata_preview\" target=\"mainFrame\">View Hotel</a><br>");
while(rs.next())
{
String dbhName= rs.getString(2).toString();
String dbhMail= rs.getString(3).toString();
String dbhId=rs.getString(1).toString();
out.println(
"<form action=\"hdata_edit\" method=\"POST\">" +
"Hotel Name :<br>" +
"<input type=\"text\" name=\"hname\" value="+dbhName+"><br>"+
"Hotel Mail :<br>" +
"<input type=\"text\" name=\"hmail\" value="+dbhMail+"><br>"+
"<input type=\"hidden\" name=\"hid\" value="+dbhId+">"+
"<br>"+
"<input type=\"submit\" value=\"SAVE\"/>" +
"</form>");
//out.println(dbhName);
}
}
catch (SQLException e){
thrownew ServletException(e);
}catch (ClassNotFoundException e){
thrownew ServletException(e);
}finally{
try{
if(rs !=null)
rs.close();
if(stmt !=null)
stmt.close();
if(con !=null)
con.close();
}catch (SQLException e){}
}
out.print("</body></html>");
out.close();
}
protectedvoid doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
String h_id = request.getParameter("hid");
String h_name = request.getParameter("hname");
String h_email = request.getParameter("hmail");
//Code to UPdate On POST the Form
}
}
[/nobr]

