Re: simple login Question

David LeBer <[email protected]>
Newsgroups gmane.comp.web.webobjects.newbies
Message-ID <[email protected]>
On Nov 26, 2004, at 10:26 AM, killerbugs19 wrote:

> hello, im a newbie to webobjects.
> I have a problem on understanding on how to integrate webobjects with
> the database particularly mySQL.
>
> Although i have a solid background on mySQL, i still don't have any
> idea as to how to connect to my database or make an SQL queries...

You're going to have to stop that :-) Try not to think SQL, try to  
think Objects.

> I already made an EOmodel and put some entities on it with the
> required attributes. I already added my EOmodel with my WOproject.
>
> My question is...
>
> 1.How do i use the EOmodel to connect to the database?

You need to set the connection dictionary in you model Model menu ->  
Set Adapter Info...

An example of a connection settings for a MySQL db is as follow:

Username: username
Password: password
URL: jdbc:mysql://localhost/big_table?capitalizeTypenames=true

Driver:
Plugin:

Once you have the correct connection dictionary set try accessing your  
db, by selecting an Entity in EOModeler, and select the "Browse Data"  
button from the toolbar. If all is good you should be able to browse  
your data.

> 2.What do i do inorder for me to make an SQL queries.
>
> I realy need to make a simple login for my authentication page.
>
> can  anyone give me an example code for this, along with the  
> explanation?

I would suggest you read the Apple documentation:

Using EOModeler:  
http://developer.apple.com/documentation/WebObjects/UsingEOModeler/ 
index.html

And work through the getting started tutorial:

Developing Web Applications:  
http://developer.apple.com/documentation/WebObjects/Web_Applications/ 
index.html

I'd also suggest you get a copy of Joshua Marker's: WebObjects 5 for  
Mac OS X: Visual QuickPro Guide
<http://www.amazon.com/exec/obidos/tg/detail/-/032111549X/ 
qid=1101484770/sr=8-1/ref=pd_csp_1/002-4101431-9286455? 
v=glance&s=books&n=507846>

Basically the kind of code you would use to log a user in would look  
something like this:

	String username; // assume exists and bound to the username WOTextField
	String password; // assume exists and bound to the password WOTextField
	// also assume that an Entity named MyUser exists in you eomodel and  
it's Java classes
	// have been generated and added to you project
	
	public WOComponent checkUserLogin() { // bound to your WOSubmitButton
		EOEditingContext ec = session().defaultEditingContext();
		NSDictionary args = new NSDictionary(new NSArray(new String[]  
{username, password}),
										new NSArray(new String[] {"username", "password"}));
		try {
			MyUser user = (MyUser)EOUtilities.objectMatchingValues(ec, "MyUser",  
args);
			// Hot dang! We got ourselves a user, Do something!
			// return somePageOrOther;	
		} catch (EOObjectNotAvailableException e) {
			// No user found, do something else.
			// return this.context().page();
		}
	}

Notice there is no SQL there, you concern yourself with Objects and  
your Model, and let WebObjects do the heavy lifting.

;david

--
David LeBer
Codebase Software Systems
site:   http://www.codebase.ca
blog: http://david.codebase.ca
smime.p7s (application/pkcs7-signature, 2.3 KB) - not displayed
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.