Sorry, i didnt know the [code] tags
Code:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
import java.util.*;
import java.sql.*;
import sun.jdbc.odbc.*;
public class JAVAPROG extends Applet
{
FlowLayout flow = new FlowLayout(FlowLayout.LEFT);
boolean isStandalone = false;
Label fnLabel = new Label("First Name: ");
Label lnLabel = new Label("Last Name: ");
Label aLabel = new Label("Adress: ");
Label vLabel = new Label("Advisor: ");
Label cLabel = new Label("Clubs: ");
Label isConnectLabel = new Label("Connected?");
TextField fnField = new TextField(55);
TextField lnField = new TextField(55);
TextField aField = new TextField(55);
TextField vField = new TextField(55);
TextField cField = new TextField(55);
TextField connectField = new TextField(55);
Button searchButton = new Button("Search");
Button cancelButton = new Button("Cancel");
Button clearButton = new Button("Clear All Text");
Button submitButton = new Button("Submit Info");
private Connection cn;
private String url;
public JAVAPROG()
{
}
public void init()
try
{
jbInit();
}
catch(Exception e)
{
e.printStackTrace();
}
}
private void jbInit() throws Exception
{
this.setLayout(flow);
add(fnLabel);
add(fnField);
add(lnLabel);
add(lnField);
add(aLabel);
add(aField);
add(vLabel);
add(vField);
add(cLabel);
add(cField);
add(isConnectLabel);
add(connectField);
add(searchButton);
add(cancelButton);
add(clearButton);
add(submitButton);
searchButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try
{
Statement state = cn.createStatement();
if (fnField.getText().equals(""))
{
isConnectLabel.setText("Valueless");
connectField.setText("You must enter a value in the 'First Name' field");
state.close();
}
else
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
url = "jdbc:odbc:JAVAPROG";
cn = DriverManager.getConnection(url);
connectField.setText("Connection Successful!");
}
catch (ClassNotFoundException cnfx)
{
cnfx.printStackTrace();
connectField.setText("Connection Unsuccessful" + cnfx.toString());
}
catch (SQLException sqlx)
{
sqlx.printStackTrace();
connectField.setText("Connection unsuccessful" + sqlx.toString());
}
catch (Exception ex)
{
ex.printStackTrace();
connectField.setText("Connection unsuccessful" + ex.toString());
}
String query = "SELECT Name FROM info " +
"WHERE Name= '" +
fnField.getText() + "'";
isConnectLabel.setText("Querying??");
connectField.setText("Sending Query!!" + cn.nativeSQL(query));
ResultSet rS = state.executeQuery(query);
display(rS);
connectField.setText("Successfull Query");
state.close();
}
}
catch (SQLException sqlex)
{
sqlex.printStackTrace();
connectField.setText(sqlex.toString());
}
}
public void display(ResultSet rS)
{
try
{
rS.next();
fnField.setText(rS.getString(1));
lnField.setText(rS.getString(2));
aField.setText(rS.getString(3));
vField.setText(rS.getString(4));
cField.setText(rS.getString(5));
}
catch (SQLException sqlx)
{
sqlx.printStackTrace();
connectField.setText(sqlx.toString());
}
}
}
);
add(clearButton);
clearButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
fnField.setText("");
lnField.setText("");
cField.setText("");
vField.setText("");
aField.setText("");
isConnectLabel.setText("Clearing Fields?");
connectField.setText("Fields Cleared...enter a new name.");
}
}
);
submitButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try
{
Statement state = cn.createStatement();
if (
fnField.getText().equals("") &&
lnField.getText().equals(""))
{
isConnectLabel.setText("No Values!!");
connectField.setText("You must enter values in the field");
}
else
{
String query = "INSERT INTO info (" +
"Name, " +
"Last Name, " +
"Advisor" +
"Clubs" +
"Adress" +
") VALUES ('" +
fnField.getText() + "', '" +
lnField.getText() + "', '" +
aField.getText() + "', '" +
cField.getText() + "', '" +
vField.getText() + "')";
connectField.setText("Sending query: " + cn.nativeSQL(query));
int result = state.executeUpdate(query);
if (result == 1)
{
isConnectLabel.setText("Submitted?");
connectField.setText("Insertion successful");
}
else
{
isConnectLabel.setText("Submitted?");
connectField.setText("Insertion unsuccessful");
}
}
}
catch (SQLException sqlex)
{
sqlex.printStackTrace();
connectField.setText(sqlex.toString());
}
}
}
);
}
public String getAppletInfo()
{
return "Applet Information";
}
public String[][] getParameterInfo()
{
return null;
}
public static void main(String []args)
{
JAVAPROG applet = new JAVAPROG();
applet.isStandalone = true;
Frame frame = new Frame();
frame.setTitle("Experimental Database Applet");
frame.add(applet, BorderLayout.CENTER);
applet.init();
applet.start();
frame.setSize(400,250);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation((d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2);
frame.setVisible(true);
}
}
I know its aweful, all and any help would be much appreciated
~Animal