views:

497

answers:

4

I am using MySql 5

Hi I am using/start learing JDBC. Well I got stuck here: After an user authenticated, I would like to start/generate the session for the user. How do I do that?

In php, I know, we can start by using the "start_session()" function. Is there any similar function in JDBC?

If there is no such kind of functions, how do we create/start session? I am really new to JDBC, so this question may sound stupid to you all, but I really cant find the answer over the internet and thats why I ask this question here. (My best resource)

Oh ya, btw, if its possible, can you include in the answer about the session destroy/delete as well? Thanks in millions

EDIT

Okay, looks like this question abit too easy(or too tough??). Maybe could try this one, is there any other way that java can unique identify an logged in user beside using session??

A: 

Maybe the JDBC programming modl doesn't look quite the same as php.

Have you tried turorials auch as this, note the use use of Statements and ResultSets. You don't see a "Session"

djna
+1  A: 

Assuming you are talking in the context of web application. There is a session provided by the Servlet container. You authenticate the user and set the credentials in the session of that user, to re-use whenever necessary, for example to know the privileges of the user etc..

Regarding JDBC, we usually go with connection pooling mechanism. So, it has nothing to do with the HTTP session of the user. We get the connection from the pool, and place it back once done. If you need to manage transaction or something you can look into JTA.

[Edited]

Try to look at the code of this Simple Login application. I am sure it will help.

Adeel Ansari
Thanks Vinegar. It does help me :)
bbtang
I am glad......
Adeel Ansari
+2  A: 

start_session in php creates a user session if it does not exist.

In the jave web app we have a HttpSession class whose instance is created by doing: request.getSession(boolean)

This call : Gets the current valid session associated with this request, if create is false or, if necessary, creates a new session for the request, if create is true.

This has nothing to do with JDBC calls - that are mainly related to connection establishment and execution of queries.

techzen
+1 for noting that star_session() doesn't have anything to do with the Database and that JDBC handles *only* the database.
Joachim Sauer
A: 

JDBC is only about interacting with databases (and things that look like them); the concept of a user session doesn't have anything to do with interacting with a database.

As the user Vinegar has suggested, if you are doing Java web development, there is a session implementation available.

I suggest you provide more info on what you are doing and if that includes some sort of web development (I'm assuming yes, since you come from a PHP background).

hbunny