Listing 1

import java.applet.*;
import java.awt.*;
import java.net.URL;
import java.util.*;
import java.sql.*;

public class JDBCSAMP extends Applet
{

	String DBurl = "jdbc:odbc:TestDB";
	String query = "SELECT * FROM Animals";


	Connection connection;
	Statement statement;
	ResultSet results;



Listing 2

Class Tmp;
try{Tmp = Class.forName ("jdbc.odbc.JdbcOdbcDriver");}
	catch(ClassNotFoundException ex)
	{
		txtDesc.setText("ClassNotFoundException: "+ex.getMessage());
		return false;
	}
		
Driver d; 
try{d = (Driver) Tmp.newInstance();}
	catch(Exception ex)
{
	txtDesc.setText("Exception: "+ex.getMessage());
	return false;
	}

if(d.jdbcCompliant() == false)
	{
	txtDesc.setText("Driver not JDBC compliant!");
	return false;
	}
	
try{
if(d.acceptsURL(DBurl)== false)
		{
		txtDesc.setText("Won't accept!");
		return false;
		}



Listing 3

Connection connection = DriverManager.getConnection (DBurl);
statement = connection.createStatement();
results = statement.executeQuery(query);



Listing 4

public void DispNextRow()
{
try
{
results.next();
	nID = results.getInt(1);
	txtName.setText(results.getString(2));
	txtHabitat.setText(results.getString(3));
	txtDesc.setText(results.getString(4));
}
catch (SQLException ex)
	{
	return;
	}

}



Listing 5

public void DeleteAnimal()
{

String Update;

try
{
	Update = "DELETE FROM ANIMALS where ID="+nID;
		
	int row = statement.executeUpdate(Update);
	if( row == 0)
		{
		lblHeading.setText("Delete Failed");
		return;
		}
	lblHeading.setText("Row: "+row);
		
	results = statement.executeQuery(query);
	DispNextRow();
				
	}
catch (SQLException ex)
	{
	return;
	}
}



Listing 6

if("Next".equals(arg))
	{
	try
{
		nPrevID = nID;
results = statement.executeQuery("SELECT * FROM ANIMALS
WHERE ID >"+nPrevID);
		} catch (SQLException ex) {return true;}
	DispNextRow();
	}
else if("Previous".equals(arg))
	{	
	nID--;
	try
	{
		results = statement.executeQuery("SELECT * FROM ANIMALS
WHERE ID="+nID);
		DispNextRow();
		}
	catch (SQLException ex)
		{
		return true;
		}
	}



Listing 7

public void stop()
{
System.out.println("I'm done!");
try
	{
		results.close();
		statement.close();
		connection.close();
	} 
catch (SQLException ex)
	{
		txtDesc.setText("SQLException: "+ex.getMessage());
	} 
}