jdbc

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

A Java PreparedStatement example with a SQL 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.

Share it!

There’s just one person behind this website; if this article was helpful (or interesting), I’d appreciate it if you’d share it. Thanks, Al.

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.

 

Share it!

There’s just one person behind this website; if this article was helpful (or interesting), I’d appreciate it if you’d share it. Thanks, Al.

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.

Share it!

There’s just one person behind this website; if this article was helpful (or interesting), I’d appreciate it if you’d share it. Thanks, Al.

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.

Share it!

There’s just one person behind this website; if this article was helpful (or interesting), I’d appreciate it if you’d share it. Thanks, Al.

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

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 Connection object.

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

Share it!

There’s just one person behind this website; if this article was helpful (or interesting), I’d appreciate it if you’d share it. Thanks, Al.

JDBC 101: How to 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.

Share it!

There’s just one person behind this website; if this article was helpful (or interesting), I’d appreciate it if you’d share it. Thanks, Al.

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.

 

Share it!

There’s just one person behind this website; if this article was helpful (or interesting), I’d appreciate it if you’d share it. Thanks, Al.

A Java JDBC exception example showing try, catch, and finally alvin October 1, 2001 - 7:52pm

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 - 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:

Share it!

There’s just one person behind this website; if this article was helpful (or interesting), I’d appreciate it if you’d share it. Thanks, Al.