I am wondering if there is a way to make a MySQL database using my java program without actually having a defined username for the admin. for example I would make a program that you could install on all computers in a network that connect to a newly made database at a location that all computers can access, then you type something in on one computer, and can see it on another when you read from the database.

is this possible? and if so how?

Thanks for the help.

Yes, you do not *have* to include the username or password.

I'm not sure if you are familiar with the database connection syntax, but you can just exclude the username and password variables from the connection string.

E.g. http://www.java-samples.com/showtutorial.php?tutorialid=9

There are alternative methods such as the grant element to allow public access but I would advise you use the standard method of connecting to a mysql database, there are numerous online tutorials where you can just exclude the usrname & pw. I haven't personally tried this as I wouldn't advise you not to use a usrname & pw in the first place.

However, even if you do include the root username and password for the mysql database in your program, the users do not see this anyway. So either way, you can successfully set up a connection to the database from all computers.

Hope that helps :)

few remarks on that..
you'll have to "make" your DB before you'll be able to use it, so the correct answer would be 'no'.
what you are looking for is more along the lines of having a centralized DB, that's not run locally on each client machine, and that can be accessed by all the clients.

sure, you can do that, but keep in mind, that if a client has no internet/network connectivity, it might not be able to use your software. anyway, a little correction to StephNicolaou's post:

However, even if you do include the root username and password for the mysql database in your program, the users do not see this anyway. So either way, you can successfully set up a connection to the database from all computers.

don't just blindly think this will always be true. every appliction, no matter how well encrypted, can be decompiled and your original source code might very well reveal itself to the one that decompiled it.

a safer option would be to have a service somewhere, and have your clients contact that service, in which you store the DB login credentials and further information. (maybe best the entire connection).

this has a few advantages:
1. no matter how many developers decompile your client app: without the code of the service, which you don't have to distribute, they won't found out about the details of your database, nor will they be able to get the password by just messing with your code.
2. if you want to change your db later on, you don't need the users of your application all to download a new version of the application, you just change the code of the service that's being connected to by all the clients. by changing that code, all work is done and life goes on as it used to, without your users even ever finding out you've switched DB's.

To clarify this is what the program would do.

check to see if database (lets say "name") exixts.
if it doesn't then it make the database name then connects
if it does then it connects.
Then it reads from the database to display words in a JLabel.
then people could click on JButtons to open that label.
Then they have an option to add, remove, and print.
if they hit add then a form comes up. if they hit remove I list all the options, and then they select which one to remove.
if they hit print, then an almost identical copy comes up, but they can order the elements, and they have a print and cancel option.

I can work with the database, but I just need to know how I would do the creating a database that multiple computers can view on the same network, but is not on the internet. (kind of like the router hosing the database).

thanks.

You would have to connect to the mysql server with the root user (or some other user with full rights), then use the standard mysql command to create the db, and to grant accesses and/or create users.

All of this, of course, assumes that a mysql server is installed and running, of course, it would take much more to install and configure the server, of course.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.