aspose file tools*
The moose likes JDBC and the fly likes how to write user defined method into doPost method in httpservlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "how to write user defined method into doPost method in httpservlet" Watch "how to write user defined method into doPost method in httpservlet" New topic
Author

how to write user defined method into doPost method in httpservlet

mohamed mustaq
Greenhorn

Joined: Dec 19, 2005
Posts: 21
Hi,
I am trying to write my own method into doPost method in HttpServlet.
i hereby enclosed my code here for clear view.
thanks.


/*
* Created on Feb 8, 2006
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package analyserQuery;

import javax.servlet.http.HttpServlet;

import java.io.IOException;
import java.io.PrintWriter;
import oracle.jdbc.OracleResultSetMetaData;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;





/**
* Servlet Class
*
* @web.servlet name="QueryAnalyser"
* display-name="Name for QueryAnalyser"
* description="Description for QueryAnalyser"
* @web.servlet-mapping url-pattern="/QueryAnalyser"
* @web.servlet-init-param name="A parameter"
* value="A value"
*/
public class QueryAnalyser extends HttpServlet
{
public void rdesc(HttpServletRequest req,HttpServletResponse res)
{
/*java.sql.ResultSet res=null;




java.sql.ResultSetMetaData res1=null;

OracleResultSetMetaData rmd=(OracleResultSetMetaData)res.getMetaData();
int columnCount=rmd.getColumnCount();

out.println("Total Number of Columns:"+columnCount+"<br>");
out.println("<html><body><table><tr><td>Coulmn Name:</td>");
out.println("<td>Coulmn Type:</td>");
out.println("<td>Coulmn Size:</td></tr>");
for(int i=1;i<=columnCount;i++)
{
String colname=rmd.getColumnName(i);
String coltype=rmd.getColumnTypeName(i);
if(coltype=="DATE")
{
colsize=rmd.getColumnDisplaySize(i);
}
else
colsize=rmd.getPrecision(i);
//int noofrows=rmd.getPrecision(i);
//int dates=rmd.getColumnDisplaySize(i);
out.println("<tr><td>"+colname+"</td>");
out.println("<td>"+coltype+"</td>");
out.println("<td>"+colsize+"</td>");

}
out.println("</table></body></html>");*/

}

public void doPost(
HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
{


String Employeenumber=null;
response.setContentType("text/html");
PrintWriter out=response.getWriter();
String uname=request.getParameter("username");

validatorBean bean=new validatorBean();
bean.setUsername(request.getParameter("username"));
bean.setPassword(request.getParameter("password"));
bean.setHost(request.getParameter("host"));
String query=request.getParameter("query");
int colsize;
try
{
bean.dbConnect();
public void rdesc(request,response);
java.sql.ResultSet res=null;

java.sql.Statement st=bean.con.createStatement();
res=st.executeQuery(query);


java.sql.ResultSetMetaData res1=null;

OracleResultSetMetaData rmd=(OracleResultSetMetaData)res.getMetaData();
int columnCount=rmd.getColumnCount();

out.println("Total Number of Columns:"+columnCount+"<br>");
out.println("<html><body><table><tr><td>Coulmn Name:</td>");
out.println("<td>Coulmn Type:</td>");
out.println("<td>Coulmn Size:</td></tr>");
for(int i=1;i<=columnCount;i++)
{
String colname=rmd.getColumnName(i);
String coltype=rmd.getColumnTypeName(i);
if(coltype=="DATE")
{
colsize=rmd.getColumnDisplaySize(i);
}
else
colsize=rmd.getPrecision(i);
//int noofrows=rmd.getPrecision(i);
//int dates=rmd.getColumnDisplaySize(i);
out.println("<tr><td>"+colname+"</td>");
out.println("<td>"+coltype+"</td>");
out.println("<td>"+colsize+"</td>");

}
out.println("</table></body></html>");

}catch(Exception e)
{
out.println(e.getMessage());
}
}//end dopost method
/*public void rdesc()
{
java.sql.ResultSet res=null;




java.sql.ResultSetMetaData res1=null;

OracleResultSetMetaData rmd=(OracleResultSetMetaData)res.getMetaData();
int columnCount=rmd.getColumnCount();

out.println("Total Number of Columns:"+columnCount+"<br>");
out.println("<html><body><table><tr><td>Coulmn Name:</td>");
out.println("<td>Coulmn Type:</td>");
out.println("<td>Coulmn Size:</td></tr>");
for(int i=1;i<=columnCount;i++)
{
String colname=rmd.getColumnName(i);
String coltype=rmd.getColumnTypeName(i);
if(coltype=="DATE")
{
colsize=rmd.getColumnDisplaySize(i);
}
else
colsize=rmd.getPrecision(i);
//int noofrows=rmd.getPrecision(i);
//int dates=rmd.getColumnDisplaySize(i);
out.println("<tr><td>"+colname+"</td>");
out.println("<td>"+coltype+"</td>");
out.println("<td>"+colsize+"</td>");

}
out.println("</table></body></html>");


}*/ //methiod redesc ends




}//servlest ends here
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42280
    
  64
OK. Do you have a question about this?


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to write user defined method into doPost method in httpservlet