Hello friends,
I have written small application which is currently deployed on Linux machine with
Tomcat 5.5 version & JDK1.5.0_06.
First I wrote normal application which contains main()
Following is the code which I have used.
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://iccs1:3306/test?user=root&password=");
This code is working absolutly fine when application is runned.
Now I want ot convert this application into web based.
For that I am using
Struts 1.2 &
JSP 1.2
Following is the code in my action
import java.io.FileOutputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.solversa.beans.excelFormBean;
/**
* @author jkl
*
* TODO To change the template for this generated type comment go to
* Window - Preferences -
Java - Code Style - Code Templates
*/
public class excelAction extends Action{
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception
{
excelFormBean beanForm = (excelFormBean)form;
Connection con;
Statement stmt;
ResultSet rs;
ResultSetMetaData rsMeta;
DataSource dataSource;
System.out.println(" File Name = " + fileName);
try
{
System.out.println(" 1 " );
/* Connection to be made to MySql for getting data & inserting it to Excel sheet */
Class.forName("com.mysql.jdbc.Driver");
System.out.println(" 2 " );
con = DriverManager.getConnection("jdbc:mysql://iccs1:3306/test?user=root&password=");
System.out.println(" 3 " );
stmt = con.createStatement();
System.out.println(" 4 " );
rs = stmt.executeQuery("Select * from Excel");
System.out.println(" 5 " );
rs.close()
con.close();
request.setAttribute("result"," created successfully.");
}
catch(Exception ee)
{
request.setAttribute("result"," not created successfully.");
System.out.println("\n\nError Found : " + ee.toString());
}
return mapping.findForward("success");
}
}
Now when ever this action is called, it rpompts me error as:
java.sql.SQLException: Unable to connect to any hosts due to exception: java.net.UnknownHostException: iccs1 While same code in normal application i.e. public static void main(
String args[]) works perfectly without any error.
Can u pls help me out.
Is this problem of JSP or Struts or Tomcat?