Solved

Have a problem to set BigInteger into MySql Select statament

Posted on 2010-08-22
8
486 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java array sort 10 63
Dynamic Table mySQL stored procedure 5 63
Get data from two MySQL tables 6 66
How does initial implicit objects  are set up in JSP? 7 41
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to implement Singleton Design Pattern in Java.

739 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