10.07.2015 Views

JDBC Developer's Guide - Supra - Cincom

JDBC Developer's Guide - Supra - Cincom

JDBC Developer's Guide - Supra - Cincom

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Step 2: Open a connection to a databaseYou open a connection to the database with the static getConnection()method of the <strong>JDBC</strong> DriverManager class. This method returns an object ofthe <strong>JDBC</strong> Connection class which needs as input a userid, password, connectstring that identifies the <strong>JDBC</strong> driver to use, and the name of the database towhich you want to connect.Connecting to a database is a step where you must enter <strong>Cincom</strong> ORDB <strong>JDBC</strong>driver-specific information in the getConnection() method.Understanding the forms of getConnection()♦♦Specifying a database URL, user id, and password:DriverManager.getConnection(String URL, String user, Stringpassword);where the URL is in the form of:jdbc:cincomordb:The following example connects user foo with password bar to a databasenamed testdb:Connection conn = DriverManager.getConnection("jdbc:cincomordb:testdb", "foo", "bar");Specifying a database URL and Properties objectDriverManager.getConnection(String URL, Properties info);where the URL is in the form of:jdbc:cincomordb:In addition to the URL, use an object of the standard Java Propertiesclass as input. For example:java.util.Properties info = new java.util.Properties();info.put ("user", "foo");info.put ("password","bar");Connection conn =DriverManager.getConnection("jdbc:cincomordb:testdb",info);Step 3: Create a Statement objectOnce you connect to the database by creating your Connection object, thenext step is to create a Statement object. The createStatement()method of your <strong>JDBC</strong> Connection object returns an object of the <strong>JDBC</strong>Statement class. Continuing the example from the previous section where wecreated the Connection object conn, now we will create the Statementobject:Statement stmt = conn.createStatement();<strong>JDBC</strong> <strong>Developer's</strong> <strong>Guide</strong>, P25-9504-03 Page 21Chapter: 3. Basic FeaturesSection: First steps in <strong>JDBC</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!