• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
JDBC Basics (In 20 Minutes Flat)
 

JDBC Basics (In 20 Minutes Flat)

on

  • 2,985 views

This is a short presentation I gave to UCI Extension employees.

This is a short presentation I gave to UCI Extension employees.

Statistics

Views

Total Views
2,985
Views on SlideShare
2,985
Embed Views
0

Actions

Likes
0
Downloads
64
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • - Good afternoon\n\n- We’re going to take a quick look at the basic elements that make up JDBC\n
  • - Talk about exactly where JDBC fits into the Java language\n\n- Then look at some examples of the 4 basic CRUD operations for databases - Create, Read, Update and Delete\n\n
  • - Enterprise developer and architect\n\n- I work with these kinds of technologies on an almost daily basis\n\n\n- How about you? Anyone with JDBC experience? How about experience connecting to databases from other languages like .NET or PHP?\n\n\n
  • - This is a quick and shallow overview of JDBC so the pre-requisites are pretty light\n\n- Hopefully you know how to write and compile simple Java programs\n\n- Also, some knowledge of basic relationaly database concepts like tables and the SQL language\n
  • - In a nutshell, JDBC is simply an API that allows you to make a connection from a Java application to a relational database and execute SQL statements against that database\n\n- It is part of the core Java APIs and has been around since very early on in Java’s life\n\n- All of the API is contained in 2 packages, java.sql contains the basic API, the javax.sql contains some more advanced API elements\n
  • - JDBC is the piece that sits between your code and the database\n\n- There is the standard API code, combined with a vendor specific Driver that knows how to talk to a particular database\n\n- In theory you can swap in a different driver and your program can work with a different database\n
  • - To initialize a Driver you simply use the standard Java classloader to load the Driver class\n\n- In this example we are loading a driver to talk to an Apache Derby database\n\n- In JavaSE 6, you don’t even need to do this, it happens in the background as part of the new Service API\n\n
  • - url is a database specific string containing information on how to connect to the database, including credentials and other details\n\n- use the DriverManager to actually create the connection\n\n- notice the error handling\n
  • - pretty basic sql table create statement\n\n- notice that Derby doesn’t support a boolean column type, so we use an integer, 0 for false, 1 for true\n\n- we have now introduced a little vendor dependency\n\n- use the connection to get a Statement object, and then execute the SQL\n
  • - once again, pretty standard SQL for inserting a row into a database\n\n- id column, name column, integer boolean column\n\n- once again we simply get a Statement object from our connection, then use it to run SQL against the database\n
  • - basic sql update statement\n\n- changing the value of the hired column to the value 1, and we use the where clause to specify which row we want to update\n\n- use the executeUpdate method call instead\n
  • - standard sql select statement, we want all columns from all rows\n\n- use the executeQuery method, which returns a ResultSet object\n\n- in this example we pass the result set to another method to print out the results\n
  • - so here is the printResults method, notice the ResultSet being passed into this method as a parameter\n\n- notice the while loop, this allows us to process each row in the result set in turn\n\n- notice the resultSet.get methods, which include a 1-based column index\n\n- if we run this code, can anyone tell me what actually gets printed to the screen?\n
  • - notice the true value for the first row, even though the value in the database was the number 1, the JDBC API was able to convert that to a boolean for us\n
  • - Of course once you have been inserting and updating data for a while, you inevitably need to delete some data\n\n- Notice the standard SQL delete statement, where we are saying to delete all rows in the candidates table whose id column has the value 888 in it\n\n- Get the Statement object from the connection and use it to run the SQL\n
  • \n
  • \n
  • \n

JDBC Basics (In 20 Minutes Flat) JDBC Basics (In 20 Minutes Flat) Presentation Transcript