
Here's the JDBC code necessary to create and execute this query: Now that we know the information we want to retrieve, how do we put this SQL statement into a Java program? It's actually very simple. In plain English, you might say "give me the last name of every customer where the salesperson id-number is 2001". This statement returns each Lname (last name) record from the Customers database, where Snum (salesperson id-number) equals 2001. To demontrate this I’ll write this simple SQL SELECT query:
#CREATING A GUI FOR MYSQL DATABASE JAVA CODE#
The hardest part of the process is defining the query you want to run, and then writing the code to read and manipulate the results of your SELECT query. Execute the SQL SELECT query you want to run.Querying a SQL database with JDBC is typically a three-step process:
#CREATING A GUI FOR MYSQL DATABASE JAVA HOW TO#
(I populated that data in my JDBC SQL INSERT tutorial.) How to perform a JDBC SELECT query against a database Here's what the Customers table looks like:Īs you can see, the Customers table contains these four sample records.

In all of these examples I’ll access a database named "Demo", and in these SELECT query examples I’ll access a database table named "Customers" that's contained in the Demo database. JDBC SELECT query: A sample databaseīefore looking at the SQL queries, let's take a quick look at our sample database.

In this SELECT query tutorial I'll take JDBC to the next step, showing how to create and execute a SQL SELECT statement in your Java code. In those examples I showed how to connect to two different databases so you could see how little the code changes when you switch from one database to another. In my JDBC connection article I showed how to connect your Java applications to standard SQL databases like MySQL, SQL Server, Oracle, SQLite, and others using JDBC.

Java JDBC FAQ: Can you share an example of a SQL SELECT query using the standard JDBC syntax? Contact me at (al) at valleyprogramming (dot) com for details. Want to work together? Your business can now hire me (Alvin Alexander) for small Scala and Flutter side projects.
