Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Have a problem to set BigInteger into MySql Select statament

Posted on 2010-08-22
8
Medium Priority
?
495 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 2000 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
Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 

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
 
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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
Recursive SQL is one of the most fascinating and powerful and yet dangerous feature offered in many modern databases today using a Common Table Expression (CTE) first introduced in the ANSI SQL 99 standard. The first implementations of CTE began ap…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

916 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