jdbc - Access to databases(JDBC Juan M Gimeno Josep M Rib o...

This preview shows page 1 - 8 out of 68 pages.

Access to databases (JDBC) Juan M. Gimeno, Josep M. Rib´ o February, 2008
Image of page 1

Subscribe to view the full document.

INDEX Access to databases: JDBC Access to databases: JDBC The JDBC approach to database access Driver loading Database connection Database manipulation Result management Errors Examples Limitations of the presented approach Appendix: The PostgreSQL DBMS 1
Image of page 2
JDBC. The Java approach to database connection INDEX The Java approach to database connection The JDBC technology provides two packages: java.sql and javax.sql which contain interfaces and classes that support the con- nection of java applications (including web applications) to databases The vendors of database management systems : Provide a specific JDBC driver which implements the in- terfaces defined in the packages java.sql and javax.sql according to the specific requirements of their database management system The java programmers : 1. Charge the JDBC driver specific for a database ma- nagement system vendor and 2. Access the database through the operations defined in the java.sql/javax.sql packages which will have been implemented in that driver 2
Image of page 3

Subscribe to view the full document.

JDBC. The Java approach to database connection INDEX Specific procedure to access a database via JDBC The procedure to connect a java application to a database can be synthesized as follows (in JDBC 1.x ): 1. Charge dynamically the specific JDBC driver (it is provided by the database manager system vendor) Class.forName("specificJDBCDriver"); 2. Open a connection to a database Connection con= DriverManager.getConnection("jdbc:DatabaseURL"); 3. Create a SQL statement and process it Statement stm=con.createStatement(); rs=stm.executeQuery("Select xxx from table ..... "); 3
Image of page 4
JDBC. The Java approach to database connection INDEX 4. Process the result set: while (rs.next()){ name=rs.getString("name"); amount=rs.getInt("amount"); } JDBC 2.0 supports further abstraction: The database can be named with a logical name without referring to the JDBC driver used This permits a higher level access to the database InitialContext ctx= new InitialContext(); DataSource ds=(DataSource) ctx.lookup("logicalNameOfTheDataSource"); This will be studied in the Design patterns for web appli- cations module (pattern Service Locator ) 4
Image of page 5

Subscribe to view the full document.

JDBC. The Java approach to database connection INDEX The java.sql and javax.sql packages The most useful interfaces and classes of these packages are: Connection A connection contains an active link to a database. It is an abstraction of an access session to a specific database A Java application can access a database through this connection A connection to a database can be obtained by: DriverManager.getConnection() or DataSource.getConnection() (JDBC 2.0) Statement It encapsulates a SQL instruction and sends it through the connection A statement is created by: Connection.createStatetment() 5
Image of page 6
JDBC. The Java approach to database connection INDEX ResultSet A set of rows which is the result of some query to the database.
Image of page 7

Subscribe to view the full document.

Image of page 8
  • Spring '16
  • dncj ncnd
  • Databases, PostgreSQL, JDBC. Database manipulation

{[ 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