Solved

Have a problem to set BigInteger into MySql Select statament

Posted on 2010-08-22
8
480 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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
netstat -ano | find "8000" and taskkill /f /pid 2984 3 56
eclipse apache tomcat admin console 52 95
mysql date time 14 28
Mysql Left Join Case 10 48
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

786 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