how can i connect my javaswing with the schools database
Posted by: g k
Date: May 02, 2005 11:14AM

i am trying to connect my java code applet with the schools database...
what and WHERE do i have to insert in my program....
NOTE: to i am using HTML file to run my applet...
NOTE: i found alot of info over the net i tryied everything, but i can not get connecteed

this is the code>


import java.awt.*;
import java.net.URL;
import java.awt.event.*;
import java.applet.Applet;
import java.sql.*;
//import javax.sql.*;
import oracle.jdbc.driver.*;


public class DatabaseDemo extends Applet implements ActionListener {
TextField place, country;
Label l1, l2;
Button b1;
//String url = "jdbc:oracle:thin:@prophet.njit.edu:1521:course";
Connection conn;
Statement stmt;

///////////////////////////////////////////////////////////////////////////////////////
public void init(){

//try{
//Class.forName(driver1);
//DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
//}
//catch (ClassNotFoundException e) {
// System.out.println ("Could not load the driver");
//}
String url = "jdbc:oracle:thin:@prophet.njit.edu:1521:course";
try{
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
/*try {
String url1 = System.getProperty("JDBC_URL");
if (url1 != null)
url = url1;
} catch (Exception e) {
System.out.println("hellothere");
// If there is any security exception, ignore it
// and use the default
}*/
}
catch (SQLException e){System.out.println("not working");}
try {
conn = DriverManager.getConnection (url, "ljtd", "jf74jd");
}
catch (SQLException e){System.out.println("not working2");}
//////////////////////////////////////////////////////////////////////////////////////////
place = new TextField(20);
country = new TextField(20);
b1 = new Button ("Submit to Location");
l1 = new Label ("Place:");
l2 = new Label ("Country:");
add(b1);
add(l1);
add(place);
add(l2);
add(country);

//place.addActionListener(this);
//country.addActionListener(this);
b1.addActionListener(this);
place.addActionListener(this);
country.addActionListener(this);

//newline = System.getProperty("line.separator");
}
////////////////////////////////////////////////////////////////////////////////////////
public void actionPerformed(ActionEvent evt){
try{
stmt = conn.createStatement();
stmt.executeUpdate("INSERT INTO location " +
"VALUES ('"+place.getText()+"', '"+country.getText()+"')");
}
catch (SQLException e){System.out.println("not working");}
//place.requestFocus();
//place.selectAll();
//country.setText(place.getText());
//country.selectAll();
}
}

///////////////////////////////////////////////////////////////////////////////////////

Options: ReplyQuote


Subject
Written By
Posted
how can i connect my javaswing with the schools database
g k
May 02, 2005 11:14AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.