jdbc

recent blog posts related to java and jdbc, including databases like mysql and postgresql

A Java PreparedStatement example with a SELECT statement and LIKE clause

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.

Java JDBC simplified - the SQLProcessor as a JDBC facade

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.

 

JDBC ResultSet metadata - the number of columns in a ResultSet

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 JDBC - a SQL SELECT query example

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.

Java JDBC Insert Example - How to insert data into a SQL table

In our first JDBC tutorial (How to connect to a JDBC database) we demonstrated how to connect your Java applications to standard SQL databases like MySQL, SQL Server, Oracle, SQLite, and others using the JDBC Connection object.

In this article we'll take the next step -- we'll show you how to insert data into a data table using Java, JDBC, and SQL.

JDBC 101 - Connect to a SQL database with JDBC

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.

HSQLDB timestamp - How to specify a default date/time

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

This is probably not the most commonly needed piece of Java code, but I've run into a situation where I have to work with a large database that for some currently-unknown reason has no foreign keys declared between tables, even though there are obviously relationships that should be defined with foreign keys.

A JDBC exception example showing try, catch, and finally

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 - a SQL INSERT example

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:

Syndicate content