| Home | Family | Softwares | Resume | Activities |
import
java.applet.Applet;
import
java.awt.*;
import
java.sql.*;
public class Enlist extends Applet
{
//Delare variable of type List
List theList;
public voidinit()
{
//Create string to store driver syntax
String url = "jdbc:odbc:PeopleData";
//Instanciate the Object theList
theList = new List(20, true);
//Create variable of type connection
Connection con;
//Create variable of type statement
Statement stmt;
//Store SQL query in a string
String query = "select * from usernames order by name";
try
{
//Load ODBC Driver by invoking Class.ForName
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(java.lang.ClassNotFoundException e)
{
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try
{
//Establish a connection is to have the appropriate driver connect to the DBMS
con = DriverManager.getConnection(url,"cn=directory manager", "password");
//Statement objects are never instanciated directly; instead a program calls the
//createStatement () method of Connection to obtain new Statement ObjectStatement
stmt = con.createStatement();
//A Resultset Object is used to store the returned query results
ResultSet rs = stmt.executeQuery(query);
while
(rs.next())
{
String s =
rs.getString("name");
String s1 =
rs.getString("surname");
String text = s + " " + s1
;
theList.add(text);
}
stmt.close();
con.close();
}
catch(SQLException
ex)
{
System.err.print("SQLException:
");
System.err.println(ex.getMessage());
}
add(theList);