What do I need to know to make a Java application that uses a database?

Since I've started using NetBeans, I've learned of some powerful ways to abstract away the process of creating Java database applications with automatically generated UI, beans bindings, and a bunch of other stuff I only vaguely understand the workings of at the moment (I hate being a newb). Problem is, how do I do the basic stuff I actually want to do? The tutorials I've read make a big deal about being able to connect to and mess around with a database from within the IDE, or how to create and bind some UI sliders and checkboxes to table columns, etc. But where can I learn about how to make my own code do that stuff? Abstraction is nice and all, but it's quite useless to me at the moment for what I need done.

Can anyone refer me to some good resources or tutorials to learn this? The few I've found aren't proving as useful as I'd hoped to get my project underway...

Asked by: Catherine847 | Posted: 28-01-2022

Answer 1

The JDBC Tutorial is a good starting point

A snippet from the intro

The JDBC API is a Java API that can access any kind of tabular data, 
especially data stored in a Relational Database.

JDBC helps you to write java applications that manage these three programming 

   1. Connect to a data source, like a database
   2. Send queries and update statements to the database
   3. Retrieve and process the results received from the database in answer to 
      your query

      The following simple code fragment gives a simple example of
these three steps:
  Connection con = DriverManager.getConnection
             ( "jdbc:myDriver:wombat", "myLogin","myPassword");

  Statement stmt = con.createStatement();
  ResultSet rs = stmt.executeQuery("SELECT a, b, c FROM Table1");
  while (rs.next()) {
    int x = rs.getInt("a");
    String s = rs.getString("b");
    float f = rs.getFloat("c");
      This short code fragment instantiates a DriverManager object to 
connect to a database driver and log into the database, instantiates a 
Statement object that carries your SQL language query to the database; 
instantiates a ResultSet object that retrieves the results of your query, 
and executes a simple while loop, which retrieves and displays those 
results. It's that simple. 

There is also a book preview on Google Books here.

Answered by: Melanie910 | Posted: 01-03-2022

Answer 2

Try the JDBC introduction from Sun.

Answered by: Ryan346 | Posted: 01-03-2022

Answer 3

One you get comfortable with JDBC, you might want to consider using Spring`s support for JDBC. It provides a much nicer API (than the standard libraries) for accessing a database via JDBC

Answered by: Anna876 | Posted: 01-03-2022

Answer 4

After reading jdbc tutorials take some attention to the base concepts: - connection - statement - query - resultset

Db authorisation belongs to conntection, query is the description of "what to do" - fetch data or update, resultset could be updatable(!) in some cases.

Answered by: Alford284 | Posted: 01-03-2022

Answer 5

The last time I looked at the JDBC tutorial, it had a lot of code examples in it that would be a recipe for SQL Injection if they were used in a real app. I had to teach a class on JDBC and I was supposed to use the tutorial, but I had to supplement it with a security lecture.

Answered by: Catherine557 | Posted: 01-03-2022

Similar questions

database - Best way to save data in a Java application?

I'm trying to find the best way to save the state of a simple application. From a DB point-of-view there are 4/5 tables with date fields and relationships off course. Because the app is simple, and I want the user to have the option of moving the data around (usb pen, dropbox, etc), I wanted to put all data in a single file. What is the best way/lib to do this? XML usually is the best format for thi...

java - How to replace MySQL Server with Apache Derby as a PHP application database?

What's the code syntax, and what all do I need to install and configure, for connecting to a Derby DB and invoking Derby Stored Procedures (which are really Java code) from a PHP Application? i.e. In the PHP code, I want to replace the familiar mysql_connect() and mysql_query() calls with something that will connect to a Derby database instead, and execute queries and stored procedures the...

database - Oracle times ten embedded in a java application

Can someone point to me some documentation on how to run the Oracle times ten database in an embedded mode within a java application? I would like to run times-ten as a replacement for HSQLDB.

How to bundle an Access database with a Java application

Hi recently I had created a Java application included database with Microsoft Access. I had wrapped it to jar file using eclipse. I pass the jar file to my friend to try to use it. But my friend told me that that is no database connection. How can i include the microsoft access in the jar file. Which mean when my friend double click the jar file it will auto configure the microsoft access database? is that possible?

java - Derby database don't save entity after application running

I'm using Embedded Derby DB with hibernate. I'm saving some entities to database. After shutting down the application there is no entities in DB. Why it could be so? Below my Hibernate configuration <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-...

database - Java Desktop application

This is a single question, but with a couple of sub questions. I am planning a Desktop application using Java and I am using NetBeans as the IDE. Questions: Why are there so many versions of Java? Java, Java SE, Java EE, Java Me I want the application to store data locally, what is best Java DB or SQLite? Do I need anything extra to create a setup file for my clients to inst...

java - H2 Database WIth .NET Application

I have created .NET APP that is supposed queries the H2 DB but at the time of "DriverManager.getConnection(DBUrl, DBUName, DBPassword);" it gives the following error: Error : IO Exception: "java.io.FileNotFoundException: Access to the path 'C:\Windows\System32\config\systemprofile\test.lock.db' is denied."; "C:\Windows\System32\config\systemprofile\test.lock.db I have accessed the H2 ...

mysql - Java application to make database dump

I needing to make a backup from my database in MySQL, with schema anda data. Anyone does know how or have some tips? Thanks

Easy database to deploy with a Java SE application

I have a Java SE application, and it uses a database. I am currently using XML files to store data, but I´m afraid it causes some errors in later use. So it would be good to use a Postgree/MySQL like DB. A real database. but the problem is, it is a commercial application, it runs under windows, and should be 2 clicks to install. I really don't like the idea of installing a database together with my application, a...

java - How to launch an application from Lotus Notes, then later save into Lotus database?

I work on a team that's developed a Java Swing application, and now I'm trying to help another team integrate this application into Lotus Notes. Unfortunately, I don't know that much about Notes, and can't seem to find any documentation related to what we're trying to do. What we want to do is have the user launch our application with some data passed in from Notes, have the user work with the passed in data, th...

windows - IE6 generated strange worksheet name when doing export from java application

I am encountering error like test(10)[1].csv file cannot be found at C:\Documents and Settings\Ron\Local Settings\Temporary Internet Files\Content.IE5\PQ0STUVW When trying to do export of CSV file using the following codes. Anyone have any idea what could be wrong? This issue does not occur in IE7 / Firefox and is only specific to IE6. response.setContentType("applicati...

c# - Embedding Flash Player in a C++ or Java application?

I would like to embed Flash Player directly inside a C++ or Java application. I found an article that describes how to do this for C#: http://www.adobe.com/devnet/flash/articles/stock_history03.html Unfortunately, I have no experience with C#, COM or ActiveX. I need someone to translate this code to C++, allowing ...

java - How best to implement user selectable variables in web application

I have a Java based web-application and a new requirement to allow Users to place variables into text fields that are replaced when a document or other output is produced. How have others gone about this? I was thinking of having a pre-defined set of variables such as : @BOOKING_NUMBER@ @INVOICE_NUMBER@ Then when a user enters some text they can specify a variable inline ...

java - BIRT in a desktop application

Did someone ever used a BIRT report in a desktop application. I'm comming from the .NET environment and there you can use Crystal Reports to show reports in desktop apps. Is this possible with BIRT too, without having to set up a server environment? Can you give me some advice how to reach this goal? Thanks in advance.

which library better for faster java application swt or swing?

which library better for faster java application swt or swing?

java - Which is the best Open source application server?

java - Access spring bean that is exposed using http invoker from GWT application

Can I access spring bean that exposed using http invoker (server) from GWT application (client)? If so is there any example / tutorial for that?

How to close a Java Swing application from the code

What is the proper way to terminate a Swing application from the code, and what are the pitfalls? I'd tried to close my application automatically after a timer fires. But just calling dispose() on the JFrame didn't do the trick - the window vanished but the application did not terminate. However when closing the window with the close button, the application does terminate. What should I do...

java - How best can I isolate my application from an unreliable database?

I have a Java SOAP data service which sits on top of a Sybase database which, for reasons out of my control, has unreliable performance. The database is part of a vendor package which has been modified by an internal team and most of the issues are caused by slow response times at certain times of the day. The SOAP service provides data to a calculation grid and when I request data, I need the response time to be ...

java - Netbeans GUI Designer & Fixed-Size Application Panels

I'm having a problem, creating a fixed-size overall panel for a touchscreen GUI application that has to take up the entire screen. In a nutshell, the touchscreen is 800 x 600 pixels, and therefore I want the main GUI panel to be that size. When I start a new GUI project in NetBeans, I set the properties of the main panel for min/max/preferred size to 800 x 600, and the panel within the 'Design' view changes size. ...

Still can't find your answer? Check out these amazing Java communities for help...

Java Reddit Community | Java Help Reddit Community | Dev.to Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)