* GREY=local LOCAL HTML version of Foils prepared 13 March 1997

Foil 17 Example - Using Imaginary's mSQL Driver

From Overview of Java Database Connection Basic Information Technology Course CPS616 -- Spring Semester 1997. by Udayan Parvate, Tom Pulikal (Geoffrey C. Fox) *

import java.net.URL;
import java.sql.*;
import imaginary.sql.*;
class Select {
public static void main (String argv[] ) {
try {
//load the class imaginary/sql/iMsqlDriver
Class.forName (" imaginary.sql.iMsqlDriver");
String url = jdbc:msql://host.npac.syr.edu:4333/test";
//connect to the test database using the driver URL
Connection conn = DriverManager.getConnection( url, "scott", "tiger");
//create the query statement and get the result set
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery (" select * from
test_table order by id");
System.out.println ("Got results :");
//print the results in a loop
while (rs.next() ) {
int a = rs.getInt(1);
String str = rs.getString(2);
System.out.println("key = " + a);
System.out.println("str = " + str); }



Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Tue Jul 22 1997