Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Java + database (MySQL?)

Options
  • 31-12-2010 2:03am
    #1
    Closed Accounts Posts: 27,857 ✭✭✭✭


    Alright folks,

    I've got a few programs that I want to develop over the next few months, and I'll be needing to store some data for them.

    Now I have very little experience working with databases in a programming context. I've used SQL quite a bit through SQL Server Management Studio, and have now downloaded HeidiSQL to mess around on my own computer, but any time I've tried to use PHP to access a database I've had trouble. Now I'm attempting to use Java to interact with the database, and I'm having a decent bit of success.

    I downloaded the JDBC API, and have ran a few test programs successfully.

    Before I push on, I just want to make sure I'm on the right path! Is using MySQL with Java a fairly normal way to go about things? If you require storage for a particular project, would it be acceptable to use MySQL?

    When I'm finished developing the program, can it be packaged up so that a user can add to/delete from the database when they execute the file? They wouldn't have to have MySQL installed for example, would they?

    Cheers... I'm fairly comfortable working with Java and with OO programming, but projects I've done have only ever required a little bit of storage as a .dat file or somethin. I've never worked on a large-scale project in a professional context for example.

    BTW the things I'm working on are not college-related, just trying to improve in my own time.

    Thanks!


Comments

  • Registered Users Posts: 981 ✭✭✭fasty


    There's nothing wrong with using Java and MySQL at all, but users will need to have access to MySQL to use it I'm afraid.

    An alternative if you want something standalone would be SQLite. I don't use Java but a quick look on StackOverflow shows that there is a JDBC driver for it that seems to work.


  • Registered Users Posts: 647 ✭✭✭Freddio


    this php implementation to connect is straight forward ->

    <?php
    $username = "database username";
    $password = "password";
    $hostname = "ip address or server name of database server";

    //connection to the database
    $dbhandle = mysql_connect($hostname, $username, $password)
    or die("Unable to connect to MySQL");

    //select a database to work with
    mysql_select_db("name of database",$dbhandle)
    or die("Could not select examples");


    //sql to execute in the php file
    $result = mysql_query("select * from table");
    while ($row = mysql_fetch_array($result)) {
    echo $row . "<br/>";
    }
    ?>


  • Registered Users Posts: 354 ✭✭AndrewMc


    Dave! wrote: »
    Before I push on, I just want to make sure I'm on the right path! Is using MySQL with Java a fairly normal way to go about things? If you require storage for a particular project, would it be acceptable to use MySQL?

    It depends entirely on what the project is. If it's a multi-user app, then a full database would be appropriate. If it's a single-user desktop thing, or even a multi-user one with relatively low traffic to the database, then SQLite might be better, as it doesn't require the user to have a full install of a DB up and running in advance; you can embed SQLite entirely within your application and the user doesn't need to know.


  • Moderators, Technology & Internet Moderators Posts: 1,335 Mod ✭✭✭✭croo


    Apache's Derby is also a very light, java based, database worth considering if a local standalone DB is required.
    http://db.apache.org/derby/
    It can also be used in a multiuser server scenario too, of course but I'm not sure of it's performance in such a case - I typically stick to postgres when such is required. MySQL's transaction support was never great without innoDB ... derby & postgres are both community based as opposed to the company controlled mySQL/innoDB which, in my mind, represented a higher risk if the controlling companies were to be sold to a less open company.


  • Closed Accounts Posts: 20,759 ✭✭✭✭dlofnep


    Hi Dave,

    For my college project in my final year - I used Apache Derby, which is an embedded database solution for java. The database is embedded within the application. It's pretty straight forward to use.


  • Advertisement
  • Closed Accounts Posts: 27,857 ✭✭✭✭Dave!


    Thanks guys, I'll look into those options.


  • Registered Users Posts: 2,089 ✭✭✭henryporter


    Don't forget that Netbeans has its own built in database creation tools, as I'm sure any other Java IDE would have.


Advertisement