• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

User name and password?

 
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, when accessing a MS-Access database, I'm using the code:

Currently I have username and password both set as "".
I'm not sure what their purpose is. I don't see any
getUsername or getPassword methods in the Connection
or Statement interfaces of the java.sql package.
So I don't have a clue what it does, the API is again
useless at explaining this.
Ideally I would like to include another table in the database
I'm accessing that contains several peoples usernames and passwords
(A username column and password column),
so that only these people can access the database, when they are prompted
to enter these two fields.
I think I could do this keeping the username and password arguments
as "", and then just checking the inputted Strings against the usernames
and passwords in the table.
Or maybe I can do it more efficiently not using the "" as arguments.
But as I said before I don't understand how it works, and the API is
useless at explaining things.
Any advice is much appreciated, thanks.
[ September 18, 2005: Message edited by: Bear Bibeault ]
 
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look at the Java docs


public static Connection getConnection(String url,
String user,
String password)
throws SQLException

Attempts to establish a connection to the given database URL. The DriverManager attempts to select an appropriate driver from the set of registered JDBC drivers.

Parameters:
url - a database url of the form jdbc:subprotocol:subname
user - the database user on whose behalf the connection is being made
password - the user's password
Returns:
a connection to the URL
Throws:
SQLException - if a database access error occurs


The username/password is the username/password of the database user. It doesn't have anything to do with data stored in the tables. To get data from your tables, you will have to execute a SQL statement
[ September 18, 2005: Message edited by: Jayesh Lalwani ]
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok, so I still need to do it as I was going to before, but what does the username and password arguments do in the code below:


Does this let you differentiate between different connections?
In the website I'm designing, different users should be able to
access and modify a MS-Acess database mdb file
(only if there username and password matches from the correct table in the database).
Do you think I should not use zero length strings as these two arguments?
The docs API doesnt explain this.
 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The username and password that you supply when you create a Connection are DB-specific. They are used to authenticate a DB user.

The user you are talking about is an application-specific user and you authorize him to access the DB and modify the table based on application-specific authorization.

SOLUTION:
1. Create a Connection to .mdb database without a username and password as you have said here.

2. Authenticate/Authorize users to access your code that interacts with the DB with this Connection. It doesn't come as a part of creating a Connection.
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, I still don't really understand how the username/password arguments work. But I'll just leave em blank and do it that way.
Thanks
 
Sravan Kumar
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let's take this example. Have you tried connecting to oracle server using SQL PLUS? You supply a username and password right? In most cases, it will be "scott" and "tiger" .. (Am i revealing too much? not really huh? )

Those are the arguments you will pass with getConnection() call. They are credentials that are configured in your DB server/software. When you create a .mdb, you do not generally provide a username and password, so you can give empty strings there.

The other name and password that you talked about is application-specific. Even to validate this, you have connect to DB first using the credentials of DB.
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok, thx. I'm pretty new to this, and I'm only using Acess databases.
I don't think I need to worry about the username/password thing to much now. But... I was thinking about synchronizing the code somehow, incase
two users where using website at same time, do u think this is important/necessary??
 
Sravan Kumar
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You, ofcourse, have to keep thread safety in mind and synchronize but tell us what kind of application is accessing the DB. Is it servlets?

An overview of your application might help us. I guess for the application you are coding right now, you do not have to put any specific code for synchronization at DB level, but, as you know, this is only my guess.

Do tell us more so we can help.
 
Sravan Kumar
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, you said website, so it must be servlets. Sorry I did not note that. I do not think you have to worry about thread safety right now, atleast, at DB level. Implicit locks must be enough.
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok, I have a JSP (kind of a welcome page to the site, that needs to accept user info) this then calls the POST method of the Data.java servlet.

The code for the JSP is shown here:


And the code for the data servlet is shwon here. You will probably notice I've had a problem (when TYPE=3 means fields need to be updated to database) updating all the fields of a single row in the database. I would like to start the for loop at 0, but for some reason, servlet doesnt do this, so I've had to update the entry for the 'Client_ID' column separatley. As you can see in the code, when TYPE=3.



Remember I need to modify the code to accept a username and password, which needs to be checked to see if it is in the database before the user can access/modify the database.
 
Jayesh Lalwani
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should not keep the values, type and rows as a member variable of your servlet. Try to refactor your code so that those variables are local variable. The reason is that if 2 clients call your servlet at the same time, your values array will be messed up

I am sorry your code is a bit hard to follow. The first thing I notice is that you should have seperate functions for showing the table and updating the table. Also, the Rownumber and type should be passed as a parameter to your servlet
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for that, yeah, there are a few errors because I just threw it together.
Im not sure how I would pass the Rownumber and type as a parameter to the servlet, I can do it with <INPUT> but not sure otherwise.
reply
    Bookmark Topic Watch Topic
  • New Topic