Results 1 to 8 of 8
  1. #1
    Ravendark is offline Member
    Join Date
    Mar 2014
    Posts
    9
    Rep Power
    0

    Default Java program that uses MySQL (creating user & database without user interaction)

    Hi,

    I have written a program that uses MySQL.
    So far, I have created a user in phpMyAdmin that uses a specific database.
    If that database does not exist, the program creates it.
    Though, in order to run, this specific user must exist. So, if a person that wants to use this program, he/she has to know how to create a mysql user with a password.

    Is there a way for the program to create a user, assign password and privileges to the user in order to interact with mysql?

    What I want is to just double click on the jar file and the program to just run. Is this possible with mysql?

    Thanks in advance.

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,367
    Rep Power
    6

    Default Re: Java program that uses MySQL (creating user & database without user interaction)

    What PHPMyadmin can do, your application can do too. But indeed you need a user with the correct capabilities before you can do anything. I mean otherwise you would be able to do security sensitive things such as altering a database without having to login at all, which means just anyone can do it.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    Ravendark is offline Member
    Join Date
    Mar 2014
    Posts
    9
    Rep Power
    0

    Default Re: Java program that uses MySQL (creating user & database without user interaction)

    So if I get that right, using java and mysql, you have to have the correct setup in order for a program to run.
    Sorry if my questions sound silly, but I am new to java and mysql, I have searched the internet but found nothing about how to create users using java.

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,367
    Rep Power
    6

    Default Re: Java program that uses MySQL (creating user & database without user interaction)

    ... that is true for any application built using any technology in any situation.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    kneitzel is offline Senior Member
    Join Date
    Feb 2014
    Posts
    447
    Rep Power
    1

    Default Re: Java program that uses MySQL (creating user & database without user interaction)

    All access to mysql (even when using mysqladmin) is done with authentication. So you always need to know a user and password.

    If you do not have to enter a username / password in mysqladmin could be, because
    - either you configured user/password somewhere already
    - maybe a default username/password is used. If I remember correctly, mysql installations tended to install with user "root" and no password.
    (So your application could use that user / password, too, but I wouldn't do that!)

    Just some thoughts on this topic:
    a) If your application is just an end user application and there is no real requirement for a stand alone SQL Server: Simply use a file based database e.g. sqlite or hsqld. Then your user does not have to do anything regarding access to a database server.
    b) if your application should run with a SQL Server: Then give the user the ability to enter user/password and the whole connection string. Users might want to have a dedicated SQL Server and multiple systems with your application.
    c) if you want the szenario b, you could still build an installer for users that want to install mysql and/or the client. Installing the server could ask the user for a password for the administrative account and also for a username / password to use for the application and maybe save it to a config-file. The installation part of the client could use such a configuration file.
    This has multiple advantages:
    - A better installation of mysql (Sorry, but installing an database server without configuring the security is something really nasty. And I like to slap such people a little bit :) )
    - An easy way to install clients because the config file is all that is required to get access.

    With kind regards,

    Konrad

  6. #6
    Ravendark is offline Member
    Join Date
    Mar 2014
    Posts
    9
    Rep Power
    0

    Default Re: Java program that uses MySQL (creating user & database without user interaction)

    Thank you konrad for your advice.
    There is no need for a mysql server. I will try to find information about sqlite. It is a hair salon software, it uses 10 or 12 tables holding information about clients appointments, products and so on.

    I really appreciate your advice

  7. #7
    kneitzel is offline Senior Member
    Join Date
    Feb 2014
    Posts
    447
    Rep Power
    1

    Default Re: Java program that uses MySQL (creating user & database without user interaction)

    Maybe I have some more ideas for you. But if I confuse you then please ignore it completely!

    You might want to move the database stuff into an interface or (abstract) class so you can have multiple implementations. That way you can have a mysql and sqlite implementation.
    So if there is a hair salon which has multiple systems, then they could install a mysql server (That is a step that they either do on their own or a good possibility to get extra money for support) and use the mysql implementation.
    The default implementation would use sqlite so there is no requirement for any complex installation. (But it will only run on a single system!).
    (You could even have some code that reads data from one database and stores it on the other.)

    There are some quite nice frameworks which support this "Dependency Injection". But the core implementation could be quite simple e.g. store the full name of the class to use inside a config variable and then load that class be name and then call the default constructor to create a new instance which you store in a variable of the type of your Interface or (abstract) class.

    With kind regards,

    Konrad

  8. #8
    Ravendark is offline Member
    Join Date
    Mar 2014
    Posts
    9
    Rep Power
    0

    Default Re: Java program that uses MySQL (creating user & database without user interaction)

    I like your way of thinking! You gave me food for thought!
    I will try to do that!
    Although there is no need, I liked it!
    Thank you very much!

Similar Threads

  1. User interaction command-line
    By kkid in forum New To Java
    Replies: 8
    Last Post: 10-29-2012, 02:37 PM
  2. How to make a Java Console Program save user made changes?
    By Chad.Curtiss in forum New To Java
    Replies: 3
    Last Post: 07-14-2012, 08:58 PM
  3. Java with MS Access Database User login
    By pateldpk in forum JDBC
    Replies: 2
    Last Post: 04-20-2012, 04:24 PM
  4. Developing an app without user interaction
    By StateMachine in forum Android
    Replies: 0
    Last Post: 12-31-2011, 08:30 AM
  5. Java program that stores user inputs
    By staticy2003 in forum Advanced Java
    Replies: 6
    Last Post: 01-24-2008, 08:46 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •