slide1
Download
Skip this Video
Download Presentation
JDBC

Loading in 2 Seconds...

play fullscreen
1 / 30

JDBC - PowerPoint PPT Presentation


  • 159 Views
  • Uploaded on

JDBC. by Jon Pearce. DBase Concepts. Terms. Table Row/Entity Column/Field/Attribute Key/Primary Key/Foreign Key. Person OID FIRST LAST ADDRESS PHONE. Address OID STREET CITY STATE. Phone OID AREA NUMBER. Entity-Relation Diagram. 1. 1. *. *. Person Table. Address Table.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' JDBC' - lamar


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
slide1

JDBC

by Jon Pearce

terms
Terms
  • Table
  • Row/Entity
  • Column/Field/Attribute
  • Key/Primary Key/Foreign Key
entity relation diagram

Person

OID

FIRST

LAST

ADDRESS

PHONE

Address

OID

STREET

CITY

STATE

Phone

OID

AREA

NUMBER

Entity-Relation Diagram

1

1

*

*

slide8
SQL
  • SELECT-FROM-WHERE
  • INSERT INTO
  • UPDATE
  • DELETE-FROM
select
Select

SELECT field1, field2, field3 ... FROM table1, table2, table3 ... WHERE condition

projection
Projection

SELECT first, last FROM Person

selection
Selection

SELECT * FROM Person WHERE last LIKE \'D%\'

slide12
Join

SELECT * FROM Person, Address WHERE Person.Address = Address.OID

insert
Insert

INSERT INTO table (field, field, ...) VALUES (value, value, ...)

update
Update

UPDATE table SET field = value, ... WHERE condition

delete
Delete

DELETE FROM table WHERE condition

jdbc driver types
JDBC Driver Types
  • JDBC-to-ODBC Bridge
  • Native API partly Java drivers
  • JDBC-Net pure Java drivers
  • Native-protocol pure Java drivers
sql browser declaration
SQL Browser Declaration

public class SQLBrowser extends Console { protected String driverName; protected String dbaseName; protected Connection connection; protected Statement statement; protected ResultSet result; public SQLBrowser(String db) throws SQLException, ClassNotFoundException {...} public void finalize() throws SQLException {...} private String toString (ResultSet rs) throws SQLException {...} public String execute(String sql) throws AppError {...}}

connecting
Connecting

public SQLBrowser(String db) throws SQLException, ClassNotFoundException { Class.forName(driverName); dbaseName = "jdbc:cloudscape:rmi:" + db; connection = DriverManager.getConnection(dbaseName); statement = connection.createStatement(); meta = connection.getMetaData();}

executing a query
Executing a Query

public String execute(String sql) throws AppError { String answer = "???"; try { result = statement.executeQuery(sql); answer = toString(result); } catch (SQLException e) { } return answer;}

processing a result set
Processing a Result Set

private String toString (ResultSet rs) throws SQLException { StringBuffer results = new StringBuffer(); ResultSetMetaData metaData = rs.getMetaData(); int numCols = metaData.getColumnCount(); for(int i = 1; i <= numCols; i++) { // get column names results.append(metaData.getColumnName(i) + "\t"); } results.append("\n"); while(rs.next()) { // get next row for(int i = 1; i <= numCols; i++) { results.append(rs.getObject(i) + "\t"); } results.append("\n"); } return results.toString();}

closing the connection
Closing the Connection

public void finalize() throws SQLException { statement.close(); connection.close();}

dbase dao
DBase DAO

public class DBaseDAO { protected String driver; protected String url; // "protocol:subprotocol:dbase" protected Connection connection; public DBaseDAO(String d, String u) throws DAOException {...} protected void connect() throws Exception {...} public void close() throws DAOException {...} protected void finalize() {...}}

connecting1
Connecting

protected void connect() throws Exception { Class.forName( driver ); connection = DriverManager.getConnection( url ); connection.setAutoCommit( false );}

ad