• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Not able to run JSP. (java.sql.SQLException: Unable to connect to any hosts )

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi vijendra,
please change the iccs1 with the ip address of the Database server. Hopely u will get the solution. Please check whether did u uploaded the .jar file for the JDBC Connection (Driver). It should be uploaded under the tomcat/common/lib folder.. Please let me know the result.


Regards
Ajay Krishnamurthy
 
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Vijendra and Ajay,

JavaRanch is a community of people from all over the world, many of who are not native English speakers. While using abbreviations like "u" instead of spelling out "you" is convenient when text messaging your friends on a cell phone or in a chat room, it presents an extra challenge to those that are already struggling with English. Additionally, such shortcuts may confound automated translation tools that patrons of the Ranch may be making use of.

I would like to ask for your help in making the content of JavaRanch a little easier to read for everybody that visits here by not using such abbreviations.

Please read this for more information.

thanks,
bear
JavaRanch Sheriff
 
Vijendra Babar
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ajay,

Its working.
I was strugling to get it, but now its working absolutly fine.

Thanks onces again.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic