Here's a quick example of how to use a JDBC PreparedStatement with an SQL SELECT query when accessing a database. To make it a little more complicated I added a LIKE clause to the SELECT statement. So, this is really an example of a PreparedStatement that uses a SELECT query that uses a LIKE clause.
recent blog posts related to java and jdbc, including databases like mysql and postgresql
I just finished a short tutorial on using an open source JDBC framework named SQLProcessor. The SQLProcessor is a facade for some of the JDBC API. It's very cool on a variety of levels, including reducing coding errors, simplifying your Java code, and providing great debug output. The tutorial is available here.
Java/JDBC ResultSet metadata
Java JDBC ResultSet metadata FAQ: How do I dynamically determine the number of columns in a Java/JDBC ResultSet?
When you send a SQL SELECT statement to a database using JDBC, you'll read the query results into a JDBC ResultSet object. We demonstrated how to do this in our article on How to Create and Execute a SQL SELECT Query.
Java SELECT query FAQ: Can you share an example of a SQL SELECT query using the standard JDBC syntax?
In our JDBC connection article we demonstrated how to connect your Java applications to standard SQL databases like MySQL, SQL Server, Oracle, SQLite, and others using JDBC. In our examples we showed how to connect to two different databases just so you could see how little the code changes when you switch from one database to another.
In my first JDBC tutorial (How to connect to a JDBC database) I demonstrated how to connect your Java applications to standard SQL databases like MySQL, SQL Server, Oracle, SQLite, and others using the JDBC
In this article I’ll take the next step and show how to insert data into a database table using Java, JDBC, and SQL.
Java database FAQ: How do I connect to a SQL database with Java and JDBC?
If you're interested in connecting your Java applications to standard SQL databases like Oracle, MySQL, SQL Server, and others, the Java JDBC technology is exactly what you need. The combination of Java/JDBC and standard SQL queries creates a simple and powerful database solution. JDBC makes the simple things easy -- without making the complex tasks too difficult either.
Here's a quick example of how to set a default value for an HSQLDB TIMESTAMP field:
create cached table directories ( dir_id identity NOT NULL, directory varchar(255) NOT NULL, time timestamp default 'now' );
There are other ways to do this, but the important line that sets the default timestamp in the above SQL is this:
time timestamp default 'now'
This is where I'm creating a timestamp field named "time" that automatically defaults to the current date/time when a record is created.
Java JDBC metadata example - A program to search for a given field name in all database tables in a database
Note: You can use the Java program below for this task, especially if you’re not using MySQL, but if you are using MySQL, you can use this query instead:
Java/JDBC try/catch/finally exception FAQ: Can you show me a decent example of how to catch a JDBC exception in a try/catch/finally block?
Beauty is in the eye of the beholder, but here's a JDBC example showing some Java code that uses a try/catch/finally block with a Java JDBC query:
Java PreparedStatement FAQ: Can you share an example of a Java
PreparedStatement that executes a SQL INSERT query?
Yes ... I just realized I don't have a Java
PreparedStatement INSERT example out here, so ... (searching, searching) ... here you go. Here's the source code for a Java/JDBC
PreparedStatement "INSERT" query example: