Solved

Have a problem to set BigInteger into MySql Select statament

Posted on 2010-08-22
8
478 Views
Last Modified: 2013-11-23
Hi Experts,

The data types for ip_start is bigint.   So, I used BigInteger for uip.  The problem here is what I should use to set the uip to the Select statement. I already try ps.setInt(1, uip) and ps.setLong(1, uip) but wrong, so, what supposed to put there.

Below is my code:
public String getUserCountry(Connection conn, String ip)throws SQLException,Exception
	{
		String country_code=null;
		BigInteger uip=null;
		try
		{
			StringBuffer query = new StringBuffer();
			query.append("SELECT country_code FROM ip_group_city where ip_start <= INET_ATON(?) ");
			query.append("order by ip_start desc limit 1");
			
			ps=conn.prepareStatement(query.toString());
			uip= new BigInteger(ip);

			ps.setLong(1, uip);  //<-----Stuck here
			
			if (log.isDebugEnabled())
				log.debug(query.toString());
		
			if(log.isInfoEnabled())
				log.info(ps.toString());
			
			ps.executeQuery();
			
			if(rs.next())
			{
				country_code=rs.getString(1);
			}			
		}	
		catch (SQLException ex) {   
			log.error("function = getUserCountry(); desc = SQL exception : " + ex.getErrorCode());
		}
		catch (Exception e)
		{
			log.error("function = getUserCountry(); desc = Exception : " + e.getMessage());
		}
		finally {
			try {
				if (rs != null) rs.close();
				if (ps != null) ps.close();
			} catch (Exception e) {
				log.error("function = getUserCountry(); desc = exception thrown : ",e);
			}
	}
		return country_code;
		
	}

Open in new window

0
Comment
Question by:sitijaafar
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 92

Expert Comment

by:objects
ID: 33498471
depends on your driver
it may not support bigint
0
 
LVL 20

Accepted Solution

by:
a_b earned 500 total points
ID: 33498487
Have you tried - ps.setInt(1, uip).intValue())  and ps.setLong(1, uip.longValue())  ??
0
 

Author Comment

by:sitijaafar
ID: 33498488
Ooo..so I cannot set BigInteger into select statement.  What I suppose use?
0
 

Author Comment

by:sitijaafar
ID: 33498503
Thanks a_b, in the database the ip_start data types is bigint.  Here is the select statement:

query.append("SELECT country_code FROM ip_group_city where ip_start <= INET_ATON(?) ");
query.append("order by ip_start desc limit 1");

So, If i'm using ps.setLong(1, uip.longValue())  is it right or wrong for set the value the ip_start -->( ip_start <= INET_ATON(?) ) in the select statement.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 20

Expert Comment

by:a_b
ID: 33498543
That would be correct.
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 33498549
BigInteger  is an object try for String
u cant premitive data type
0
 
LVL 92

Expert Comment

by:objects
ID: 33498616
what driver?
0
 

Expert Comment

by:spavithracse
ID: 33509733
Actually it is the Type of Integer. Have u tried with using setInt or else use setBigInt() there
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now