File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes servlet, mysql JDBC connection and Parameters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "servlet, mysql JDBC connection and Parameters" Watch "servlet, mysql JDBC connection and Parameters" New topic

servlet, mysql JDBC connection and Parameters

induz sat

Joined: Aug 06, 2013
Posts: 18
I want to have multiple JDBC-connections (to mySQL databse) in my servlet.

For each servlet I use:

After establishing JDBC connection to SocialNetwork DataBase, I use insert, and update queries to add/update the records on my userInfo db.

i want the same JDBC connection to use in another servlet[userLogin] in the same application/package.

Is there a way I can create another connection servler/class and import it and use it in all other Httpservlets responsible for registering a new user , checking records, updating records the same SocialNetwork Db but different tables??

The 'UserLogin' servlet checks two records userName and Password in 'registredUser' table when the user logs-in through a login.jsp page with userName and password.

I am getting input parameters onto the UserLogin servlet from Login.jsp as below

How should i go about checking name and password in terms of sql queries- right now I am trying to use

to make it clear I have 2 tables[ registredUser and UserInfo.
RegistredUser has these colums- UserId, userName, Password, Age and city. user Id is PK and AI.

UserInfo has userId, userName and Password. User Id is PK and AI in this table too.

How can i establish a relation between userID in two different tables and check/authenticate the userName and password??

Ivan Jozsef Balazs

Joined: May 22, 2012
Posts: 970
Some side notes:

  • Database connections in servlet environments are best used through connection pools.
  • Hardwiring the database parameters into the source code is not good.
    I agree. Here's the link:
    subject: servlet, mysql JDBC connection and Parameters
    It's not a secret anymore!