• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 508
  • Last Modified:

Have a problem to set BigInteger into MySql Select statament

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
sitijaafar
Asked:
sitijaafar
  • 2
  • 2
  • 2
  • +2
1 Solution
 
objectsCommented:
depends on your driver
it may not support bigint
0
 
a_bCommented:
Have you tried - ps.setInt(1, uip).intValue())  and ps.setLong(1, uip.longValue())  ??
0
 
sitijaafarAuthor Commented:
Ooo..so I cannot set BigInteger into select statement.  What I suppose use?
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
sitijaafarAuthor Commented:
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
 
a_bCommented:
That would be correct.
0
 
Sathish David Kumar NArchitectCommented:
BigInteger  is an object try for String
u cant premitive data type
0
 
objectsCommented:
what driver?
0
 
spavithracseCommented:
Actually it is the Type of Integer. Have u tried with using setInt or else use setBigInt() there
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

  • 2
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now