10 Replies - 3614 Views - Last Post: 24 January 2010 - 02:46 PM Rate Topic: -----

#1 gda2004   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 111
  • Joined: 08-January 09

Selecting a single record in a Ms Access Database ?

Posted 24 January 2010 - 01:30 PM

could anyone tell me how to select all the columns from a table which meets only one criteria i.e select a single record

 "SELECT [Account_Number],[Holders_Name],[Holders_Address],[Street_Name],[Post_Code],[Overdraft_Limit],[Balance]"+
						" FROM Accounts WHERE [Account_Number] = '" + Account_Number + "';";


This is what i am using at present it returns the account number fine from the table but the rest of them are null I have also tried
select *


Many thanks

Gda2004

Is This A Good Question/Topic? 0
  • +

Replies To: Selecting a single record in a Ms Access Database ?

#2 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3744
  • View blog
  • Posts: 17,121
  • Joined: 20-September 08

Re: Selecting a single record in a Ms Access Database ?

Posted 24 January 2010 - 01:52 PM

Can you print out the above string please?
Was This Post Helpful? 0
  • +
  • -

#3 gda2004   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 111
  • Joined: 08-January 09

Re: Selecting a single record in a Ms Access Database ?

Posted 24 January 2010 - 01:57 PM

View Postg00se, on 24 Jan, 2010 - 12:52 PM, said:

Can you print out the above string please?



SELECT [Account_Number],[Holders_Name],[Holders_Address],[Street_Name],[Post_Code],[Overdraft_Limit],[Balance] FROM Accounts WHERE [Account_Number] = '000002
';



I don't know why the last single quote is like that thats how eclipse printed it out

many thanks

gda2004
Was This Post Helpful? 0
  • +
  • -

#4 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3744
  • View blog
  • Posts: 17,121
  • Joined: 20-September 08

Re: Selecting a single record in a Ms Access Database ?

Posted 24 January 2010 - 02:10 PM

That looks ok to me - how many records are found?
Was This Post Helpful? 0
  • +
  • -

#5 gda2004   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 111
  • Joined: 08-January 09

Re: Selecting a single record in a Ms Access Database ?

Posted 24 January 2010 - 02:17 PM

View Postg00se, on 24 Jan, 2010 - 01:10 PM, said:

That looks ok to me - how many records are found?



its strange because it does give me the record i want being 000002 but after that its null what i mean is

 answerBack =String.valueOf("bk"+"*"+Account_Number +"*"+Holders_Name+"*"+Holders_Address+"*"+Street_Name+"*"+Post_Code+"*"+Overdraft_Limit+"*"+Balance+"*");


bk*000002
*null*null*null*null*null*null*



that is the message i am sending back to my server from database class I have checked my database and there is data in those fields so i do not know what is going on. I am using a string tokenizer at the other end to split it up

Many thanks

gda2004
Was This Post Helpful? 0
  • +
  • -

#6 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3744
  • View blog
  • Posts: 17,121
  • Joined: 20-September 08

Re: Selecting a single record in a Ms Access Database ?

Posted 24 January 2010 - 02:21 PM

How are you handling the ResultSet?
Was This Post Helpful? 0
  • +
  • -

#7 gda2004   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 111
  • Joined: 08-January 09

Re: Selecting a single record in a Ms Access Database ?

Posted 24 January 2010 - 02:29 PM

View Postg00se, on 24 Jan, 2010 - 01:21 PM, said:

How are you handling the ResultSet?



				ResultSet statResult = statObject.executeQuery(SQLQueryFinal);
				System.out.println("after the querry");
				while (statResult.next()) {

					Account_Number = statResult.getString(0);
					System.out.println(Account_Number);
					System.out.println("12345678");
					Holders_Name = statResult.getString(1);
					System.out.println(Holders_Name);
					Overdraft_Limit = statResult.getString(2);
					Holders_Address = statResult.getString(3);
					Street_Name= statResult.getString(4);
					Post_Code= statResult.getString(5);
					   Overdraft_Limit= statResult.getString(6);
				   Balance = statResult.getString(7);
				}



However i discovered i had forgotten to put a \n on the messege going into the database class
so i corrected my mistake and now i have this error

SELECT [Account_Number],[Holders_Name],[Holders_Address],[Street_Name],[Post_Code],[Overdraft_Limit],[Balance] FROM [Accounts] WHERE [Account_Number] = '000002';
after the querry
[Microsoft][ODBC Driver Manager] Invalid descriptor index



Many thanks

gda2004
Was This Post Helpful? 0
  • +
  • -

#8 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3744
  • View blog
  • Posts: 17,121
  • Joined: 20-September 08

Re: Selecting a single record in a Ms Access Database ?

Posted 24 January 2010 - 02:32 PM

Indexes start at 1, not 0
Was This Post Helpful? 0
  • +
  • -

#9 gda2004   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 111
  • Joined: 08-January 09

Re: Selecting a single record in a Ms Access Database ?

Posted 24 January 2010 - 02:38 PM

View Postg00se, on 24 Jan, 2010 - 01:32 PM, said:

Indexes start at 1, not 0



				while (statResult.next()) {

					Account_Number = statResult.getString(1);
					System.out.println(Account_Number);
					System.out.println("12345678");
					Holders_Name = statResult.getString(2);
					System.out.println(Holders_Name);
					Overdraft_Limit = statResult.getString(3);
					Holders_Address = statResult.getString(4);
					Street_Name= statResult.getString(5);
					Post_Code= statResult.getString(6);
					   Overdraft_Limit= statResult.getString(7);
				   Balance = statResult.getString(8);
				}

I have just changed it so it starts at one I am futher into the loop but it seems to still fall over
[Microsoft][ODBC Microsoft Access Driver]Invalid descriptor index

it seems to be the messege being sent back which is the issue

answerBack =String.valueOf("bk"+"*"+Account_Number +"*"+Holders_Name+"*"+Holders_Address+"*"+Street_Name+"*"+Post_Code+"*"+Overdraft_Limit+"*"+Balance+"*");


Many thanks

gda2004
Was This Post Helpful? 0
  • +
  • -

#10 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3744
  • View blog
  • Posts: 17,121
  • Joined: 20-September 08

Re: Selecting a single record in a Ms Access Database ?

Posted 24 January 2010 - 02:42 PM

I'm not over-familiar with the weird proprietary square bracket stuff with Access, but try getting rid of the brackets from the table name
Was This Post Helpful? 0
  • +
  • -

#11 gda2004   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 111
  • Joined: 08-January 09

Re: Selecting a single record in a Ms Access Database ?

Posted 24 January 2010 - 02:46 PM

View Postg00se, on 24 Jan, 2010 - 01:42 PM, said:

I'm not over-familiar with the weird proprietary square bracket stuff with Access, but try getting rid of the brackets from the table name


I solved the problem it was the fact that i was trying to take in to many variables i only had 7 fields i duplicated one by mistake

 while (statResult.next()) {

					Account_Number = statResult.getString(1);
					System.out.println(Account_Number);
					System.out.println("12345678");
					Holders_Name = statResult.getString(2);
					System.out.println(Holders_Name);
					
					Holders_Address = statResult.getString(3);
					System.out.println(Holders_Address);
					Street_Name= statResult.getString(4);
					System.out.println(Street_Name);
					Post_Code= statResult.getString(5);
					System.out.println(Post_Code);
					   Overdraft_Limit= statResult.getString(6);
					   System.out.println(Overdraft_Limit);
				   Balance = statResult.getString(7);
				   System.out.println(Balance);
				}


ingoure the print statements but it now works i am very greatfull for your help i would of not realised it unless you had not of pointed out the indexes to me

once again thanks

gda2004
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1