0
String Ipnumbers = request.getParameter("Ipnumbers");
String variant = request.getParameter("variant");
String strQuery = "SELECT Ipnumbers, username FROM brane where val(Ipnumbers) ";
if (Ipnumbers.equal("superior"))
  strQuery += "> " + Ipnumbers ;

I have in my MS Access database a list of IP numbers (192.03.34.44) declared as text. How can I use a user search form (user input field named Ipnumbers) to query my database? The question is- what is the declaration format or how to convert from string to whatever these dotted numbers are- to be recognised by Java. Cheers. Example: I did the same for integer value I have in my database like:

  int nStudentnumbers = Integer.parseInt(Studentnumbers);

how can use or parse the dotted IP numbers as? They are not integer neither double? Cheers

Brane
  • 139
  • 1
  • 2
  • 6

1 Answers1

3

You should have to use PreparedStatement,

String strQuery = "SELECT Ipnumbers, username FROM brane where Ipnumbers=?";
PreparedStatement statement=connection.prepareStatement(strQuery);
statement.setString(1,Ipnumbers);
KV Prajapati
  • 93,659
  • 19
  • 148
  • 186
  • thanks for your reply, I am having problem with parsing the dotted IP numbers in my queries. I have updated my question :) – Brane Aug 21 '12 at 10:44
  • @Brane - Take a look at post - [Sort IP addresses in an Access database](http://office.microsoft.com/en-us/access-help/sort-ip-addresses-in-an-access-database-HP001164613.aspx) - They've split Ip string into four parts. – KV Prajapati Aug 21 '12 at 11:49
  • thanks buddy, I just read your post but it doesn't answer my question :( , my problem is actually how to parse Ipnumbers in my query, like can i declare it as int nIpnumbers = Integer.parseInt(Ipnumbers); ? – Brane Aug 21 '12 at 12:01
  • I know that (you can use replace(ip,'.','') MSAccess func to remove dot) but there isn't *straight* way to parse IP string into *int* at database level. – KV Prajapati Aug 21 '12 at 12:11
  • Something like - `SELECT val(replace(Ipnumbers,'.','')) as Ipnumbers,username from tableName where val(replace(Ipnumbers,'.',''))>=?` - (have not tested) – KV Prajapati Aug 21 '12 at 12:20
  • thanks, I have just tested your code, it does not work , I get the following error, `java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in number in query expression 'val(replace(Ipnumbers,'.','')) > 192.145.66.23'.` – Brane Aug 21 '12 at 12:31