I’ve recently started my first programming job, and what I need to do as my main project is to create a program for simulating diesel generator behaviour.
I’m creating this program using Java, which I’ve never used before (all of my limited experience is with C++), and the first problem I need to overcome is to create a database to store the necessary data that will act as input to the simulator.
This database problem strikes me as something that has, in general, been done many times before. Could anyone get me started on the right track towards achieving this with suggestions on what to use to first create the database, and then what to use to access it with the simulator? In regards to the latter, I’ve been reading over the java.sql package, and it seems as though it would suit my purposes. What do you think?
Thanks very much in advance.
There are 2 parts to your question: how to create a database, and how to access it from your code.
Part 1: there are several light-weight database projects that you can choose from. Check out HSQLDB, it’s quite popular and user-friendly. You’ll have to download it, and you can use the built-in tools to create and populate your database with data.
Part 2: The JDBC standard defines how a Java program connects to the database. The tutorial (as suggested by amarillion) is a good place to start. You’ll need to put the database’s JDBC driver in your classpath, and you’ll be able to connect to the DB from your code. Note that parts of the process (such as the driver and the connection string) are specific for the database you choose (meaning, the connection string for HSQLDB is different from the one for MySQL).
However, JDBC is rather low-level: you have to work with objects that represent connections and SQL statements (the ones you noticed in
java.sql). This is an excellent place to start, but later on, as your code grows, you might want to consider using an O/R mapping tool. It will make your life easier, but it has a learning curve. The most popular ORM for Java is Hibernate.Good luck!