JavaDB:Introduction to JDBC

From Juneday education
Jump to: navigation, search

Full frontal - Code up-front

We don't expect you to understand the following code, but believe that it's always good to be exposed to code early on.

try (Statement stm = con.createStatement() ) { // try-with-resources
  String query = "SELECT Name, HTTPS FROM municipalities LIMIT 5";
  ResultSet rs = null;
  rs = stm. executeQuery(query);

  while ( rs.next() ) {
    System.out.println(rs. getString("Name") + " " +
                      (rs. getBoolean("HTTPS") ? "HTTPS support" : "HTTP only") );
  }
} catch (SQLException sqle) {
  System.err.println(sqle.getMessage());
}

Introduction

This chapter introduces you to the basics of using the JDBC API for using databases with Java.

We will introduce some of the interfaces in java.sql like:

  • Connection
  • Statement
  • ResultSet

And some of the classes:

  • DriverManager
  • SQLException

We encourage you to read the external resources (further reading links) below, after watching the video.

Requirements

In order to fully understand this chapter, we assume you have basic knowledge of SQL and SQLite. If you feel that you need to freshen up on SQL, we recommend our book Introduction to Databases.

Lecture slides and videos

English videos

No English videos yet, but we are planning to make some soon!

Swedish videos

Links

External links

Chapter links

After this chapter you should move on to the Exercise - Introduction to JDBC chapter.