GIDForums  

Go Back   GIDForums > Computer Programming Forums > Java Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 29-Feb-2008, 04:12
asdfg asdfg is offline
New Member
 
Join Date: May 2007
Posts: 26
asdfg is on a distinguished road
Lightbulb

How Can I Check on Database


Dear all,

I have the problem on Inserting the Database Table field I need to check that entry already in that tables If there I want to produce error message and want to produce the message to re enter only that error data.

This piece of code that, I used to inserting data from the keyboard to produce the one Class object return values, After that I'll going to insert on the Database.

But the thing is How Can I check after entering University ID, I want to check that data already stored in database or not????

JAVA Code:
public static Member gettingInputFromUser(){
		System.out.println(" This is the Function Cluster to get Data from keyBoard");
		
		Member mbr= new Member();
		String nm = Reade.readentry("Enter University ID		 	:  ");
			
		mbr.setUniversityId(nm); 
		
		
		nm = Reade.readentry("Enter Name 			:  ");// read mmeber ID 17 char
		mbr.setName(nm); // mbr is an instace of the member Class
		
		nm = Reade.readentry("Enter Member ID		 		:  ");
		mbr.setMemberId(nm); // here we have to chang this, that as automatic adding the  Member ID
		 
		 
		nm = Reade.readentry("Enter Member Catergory	:  ");
					mbr.setRegisteredCategory(nm); 
		// Start date receiver
					mbr.setRegisterdDate(getCurrentJavaSqlTimestmp()); // date set 
				 	mbr.setRenewalDate( getCurrentJavaSqlTimestmp()); // Innitially Both are Same
				 	return mbr;
	}
	


I will get out put like this while the piece of code executing

Quote:
Enter University ID : SEU/IS/01/BS/17

Enter Name : Abdul Haleem
Enter Member ID : 555
Enter Member Catergory : STU

Each line prints(Black in color), I'll enter the details(Green In color) and pres enter key.

My problem is how can i check that database consist that University Id on our Database.

Please try to solve this problem soon.
  #2  
Old 29-Feb-2008, 09:06
TurboPT's Avatar
TurboPT TurboPT is offline
Regular Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 956
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: How Can I Check on Database


I'm assuming, that there is some sort of DB connectivity to the application, and not a "memory-based" DB scheme...(like link-listing?)

Anyway, query the database to see if the ID already exists.

To me, it seems that generating an error might be 'overkill'. Prechecking the ID, and if one exists, then simply use that ID to associate the other information in the related table. [this assumes a good relational model, of course]

So, the query, depending on the table design around the 'University ID' might use one of these general SQL formats:
Code:
SELECT <id> FROM <university> WHERE <id>='SEU/IS/01/BS/17' // or maybe (assuming that 'ID' and 'university' are two different fields) SELECT <id> FROM <university> WHERE <some-other-column>='SEU/IS/01/BS/17'
If a value is given after SELECT, then the ID exists; otherwise, the entry is new. This check might best be done in the setUniversityId() handling, but that's just a guess.
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #3  
Old 29-Feb-2008, 19:50
asdfg asdfg is offline
New Member
 
Join Date: May 2007
Posts: 26
asdfg is on a distinguished road
Question

Re: How Can I Check on Database


Tahnk you turbo,
In my case Taht I thought Before reading all Data from the user I'll generate the message to user that "You gave University ID's person already registered on the Libray System" otherwise It will allows to read the rest of the date from the user.

Ya you got my point I have created Databas using MySQL, I have thought like

Enter University ID : SEU/IS/01/BS/17

" After this going to check"
Then if the data alraedy exists call repeatedly Enter University ID :

Otherwise calling rest of the parts as follows,

Enter Name : Abdul Haleem
Enter Member ID : 555
Enter Member Catergory : STU


Did you got my view ?
  #4  
Old 29-Feb-2008, 21:59
TurboPT's Avatar
TurboPT TurboPT is offline
Regular Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 956
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: How Can I Check on Database


Yes, I think the "...already registered..." message is better than an error.

However, think about this: the University ID, by itself, might not be enough to tell that someone is "already registered", but of course I don't know what the codes in your University ID indicate. (because if the University ID is merely a course reference, surely more than one person will be allowed to take that course!)

It might be necessary to get the University ID and maybe a member ID pair to get a true, specific registration.
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #5  
Old 01-Mar-2008, 02:06
asdfg asdfg is offline
New Member
 
Join Date: May 2007
Posts: 26
asdfg is on a distinguished road
Exclamation

Re: How Can I Check on Database


Dear Turbo,

University_ID is the Unique key for an student or staff in the university but in my Librarysystem Database memberID is the primary Key.

But I thought any one situation some one may tries to register twice by the mistakes, so I thougt to eleminate the constraints at the beginning of the entering database.

Afeter checking all the values charect format, final result of the information want to stores on the Database.

this is my member class :

JAVA Code:
ackage librarySystemV5;

/// Completed Member Class version / final 29.02.2008
/*Author S.L. Abdul Haleem*/

public class Member {

			static String name;
			static String memberId;
			static String universityId;
			static java.sql.Timestamp registerdDate;
			static  java.sql.Timestamp renewalDate;
			static String registeredCategory;
							
			public String getName(){return name;}
			//get the output Name of the Library Member
			public void setName(String aname){	name = aname;}
			//set Name on the objectClass
			public String getMemberId(){return memberId;}
			//Get memberID
			public void setMemberId(String aMemberId){memberId = aMemberId;}
			//setup member Id 			 
			public String getUniversityId(){	return universityId; }
			//get unversity ID						
			public void setUniversityId(String aUniversityId){universityId = aUniversityId;} 
			//setup university Id		 		 
			public java.sql.Timestamp getRegisterdDate(){return registerdDate;}	 
			// get the date time of registration as 2008-02-29 18:40:30.343	
			public void setRegisterdDate(java.sql.Timestamp aRegisterdDate){registerdDate = aRegisterdDate;}  		
			// set Registered date as on registering database 
			public java.sql.Timestamp getRenewalDate(){return renewalDate;}	  
			// get renewal dates			
			public void setRenewalDate(java.sql.Timestamp aRenewalDate){renewalDate = aRenewalDate;} 	 
			// set renewal date
			public String getRegisteredCategory(){return registeredCategory;}
			// get registered cattergorry
			public void setRegisteredCategory(String aRegisteredCategory){registeredCategory = aRegisteredCategory;} 
			//set registeredcattergorry
} // End of the Member Class

  #6  
Old 01-Mar-2008, 06:57
TurboPT's Avatar
TurboPT TurboPT is offline
Regular Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 956
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: How Can I Check on Database


Quote:
Originally Posted by asdfg
Dear Turbo,

University_ID is the Unique key for an student or staff in the university but in my Librarysystem Database memberID is the primary Key.

But I thought any one situation some one may tries to register twice by the mistakes, so I thougt to eleminate the constraints at the beginning of the entering database.

That's ok by me. If what you have works for you then that's fine, because you know what you need for your application, I was just pointing out a potential problem to consider.
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #7  
Old 01-Mar-2008, 08:19
asdfg asdfg is offline
New Member
 
Join Date: May 2007
Posts: 26
asdfg is on a distinguished road
Exclamation

Re: How Can I Check on Database


Dear turbo,

i asked some problem on my private post, please give me some suggestion.
 
 

Recent GIDBlogFlickr uploads of IA pictures by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help understand function prototypes! Blstretch C++ Forum 20 25-Oct-2005 14:14
Help with Classes and database arrays brookeville C++ Forum 1 13-Apr-2005 00:26
Limit combo box and date time picker choice according to database created in folder shinyhui C++ Forum 0 22-Feb-2005 20:16
Limit combo box and date time picker choice according to database created in folder shinyhui MS Visual C++ / MFC Forum 0 22-Feb-2005 02:13

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 17:58.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.