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

Info icon This 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.
Image of page 1

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

View Full Document Right 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/
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.
Image of page 3

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

View Full Document Right Arrow Icon
SqliteJDBC Documentation 4 http://www.zentus.com/sqlitejdbc/
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
Image of page 5

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

View Full Document Right 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
Image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern