JDBC - CS 580 Client-Server Programming Spring Semester,...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 580 Client-Server Programming Spring Semester, 2010 Doc 17 JDBC 8 April, 2010 Copyright ©, All rights reserved. 2010 SDSU & Roger Whitney, 5500 Campanile Drive, San Diego, CA 92182-7700 USA. OpenContent ( http:// www.opencontent.org/opl.shtml ) license defines the copyright on this document.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
References 2 http://java.sun.com/javase/6/docs/technotes/guides/jdbc/index.html Sun's on-line JDBC Tutorial & Documentation SqliteJDBC Docs, http://www.zentus.com/sqlitejdbc/
Background image of page 2
Java – Connecting To Database 3 import java.sql.*; public class Test { public static void main(String[] args) throws Exception { Class.forName("org.sqlite.JDBC"); Connection conn = DriverManager.getConnection("jdbc:sqlite:test.db"); Statement stat = conn.createStatement(); stat.executeUpdate("drop table if exists people;"); stat.executeUpdate("create table people (name, occupation);"); PreparedStatement prep = conn.prepareStatement( "insert into people values (?, ?);"); prep.setString(1, "Gandhi"); prep.setString(2, "politics"); prep.addBatch(); conn.setAutoCommit(false); prep.executeBatch(); conn.setAutoCommit(true); ResultSet rs = stat.executeQuery("select * from people;"); while (rs.next()) { System.out.println("name = " + rs.getString("name")); System.out.println("job = " + rs.getString("occupation")); } rs.close(); conn.close(); } This is the old way (Pre Java 6) of connecting.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
SqliteJDBC Documentation 4 http://www.zentus.com/sqlitejdbc/
Background image of page 4
JDBC 5 Java Program JDBC Driver Manager Oracle Driver MM MySQL Driver Oracle Database MySQL Database JDCB-ODBC Driver ODBC Database etc. Drivers must be in your classpath
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
JDBC Drivers 6 Java supports four types of JDBC drivers JDBC-ODBC bridge plus ODBC driver Java code access ODBC native binary drivers ODBC driver accesses databases ODBC drivers must be installed on each client Native-API partly-Java driver Java code accesses database specific native binary drivers JDBC-Net pure Java driver Java code accesses database via DBMS-independent net protocol Native-protocol pure Java driver Java code accesses database via DBMS-specific net protocol
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 24

JDBC - CS 580 Client-Server Programming Spring Semester,...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online