* 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) *

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

Table Font Size


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