Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to convert Long to String.

 
Preethi jaya
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to convert Long to String.

long locationId = 0;

while (rs.next())
{
locationId = rs.getLong("LOCATIONID");
LocationInfoHelper locationInfohelper = new LocationInfoHelper();
String localTime = locationInfohelper.getLocalTimeForLocation(locationId);
}

I am getting below error.

getLocalTimeForLocation(int,javax.servlet.http.HttpServletRequest) in com.apr.swd.servlet.helper.LocationInfoHelper cannot be applied to (long)
String localTime = locationInfohelper.getLocalTimeForLocation(locationId);
[javac] ^
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] 1 error
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65227
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please take the time to choose the correct forum for your posts. This forum is for questions on Servlets.

For more information, please read this.

This post has been moved to a more appropriate forum.

 
Saifuddin Merchant
Ranch Hand
Posts: 607
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ehhh ..Where are you converting 'long to String'?

The line that does not compile is locationInfohelper.getLocalTimeForLocation(locationId); and the reason is also pretty clear - the function getLocalTimeForLocation(int,javax.servlet.http.HttpServletRequest) is defined with another set of parameters.

Are you coding for a web application? Are you using Servets/jsp?

Little more details about what you are trying to achieve please?
 
Fred Hamilton
Ranch Hand
Posts: 684
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Based on your question and the info you provided, I'm guessing the function call

locationInfohelper.getLocalTimeForLocation(locationId);

wants locationId to be a string. So...

There is a class called Long which has a method toString(long d) which should do the trick

good luck with it
 
Saifuddin Merchant
Ranch Hand
Posts: 607
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fred Hamilton wrote:Based on your question and the info you provided, I'm guessing the function call

locationInfohelper.getLocalTimeForLocation(locationId);

wants locationId to be a string. So...

There is a class called Long which has a method toString(long d) which should do the trick

good luck with it


Sorry but I am not sure where you got this from? The signature of getLocalTimeForLocation is getLocalTimeForLocation(int,javax.servlet.http.HttpServletRequest) -- requires a int and HTTPServletRequest object not a String.
 
Fred Hamilton
Ranch Hand
Posts: 684
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sam Mercs wrote:
Fred Hamilton wrote:Based on your question and the info you provided, I'm guessing the function call

locationInfohelper.getLocalTimeForLocation(locationId);

wants locationId to be a string. So...

There is a class called Long which has a method toString(long d) which should do the trick

good luck with it


Sorry but I am not sure where you got this from? The signature of getLocalTimeForLocation is getLocalTimeForLocation(int,javax.servlet.http.HttpServletRequest) -- requires a int and HTTPServletRequest object not a String.


duly noted. I withdraw the comment "I'm guessing the function call locationInfohelper.getLocalTimeForLocation(locationId); wants locationId to be a string. " with apologies for a very careless remark.

However, the question was "How to convert a long to a String" at least my answer to that question is correct, although it is no longer clear why the question is relevant to the problem. Maybe the poster doesn't know the method wants an int?
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well,

in other hand , you can do like below

 
Fred Hamilton
Ranch Hand
Posts: 684
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
seetharaman venkatasamy wrote:well,

in other hand , you can do like below



or this...


 
Rob Spoor
Sheriff
Pie
Posts: 20669
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anyway, you should avoid "new Long", "new Integer" and all others. Since Java 5.0 all of the primitive-wrapper classes have a static method called "valueOf" which takes a matching primitive, and returns a wrapper instance (e.g. Character.valueOf('a'), Boolean.valueOf(true), Integer.valueOf(4)). The advantage of using "valueOf" over "new" is that "valueOf" may return any cached objects.
For instance, Byte, Short, Integer and Long keep objects for all values between -128 and 127 in a cache. Character similarly has a cache for 0 to 127 (a.k.a. the ASCII characters), and Boolean.valueOf returns either Boolean.TRUE or Boolean.FALSE - static final Boolean objects that represent the only two choices.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic