I'm in need of some help rather fast, project due!!
I am so new to java and I have this project due and the boss is breathing down our necks, anyway I need to know how to call some classes. I have this button on an applet from which I need to trigger the following class.
void va_MouseClicked(java.awt.event.MouseEvent event)
{
I need to pass a string or label to my class.
}
This is my query class, now I need to make several of these, I'm just not sure how to put all three of my class to work together. I think I'm really missing something here, just not sure what.
import java.awt.*;
import java.io.*;
import java.sql.*;
import java.net.URL;
public class BRR extends Object {
JVRConn conn;
public BRR(JVRConn _conn) {
conn = _conn;
String specLiab;
PreparedStatement prepstmt;
// the labelspecliab is what I need to retrieve from my button,
// I can either pass this as a label or string.
specLiab = ces.labelspecliab.getText().toString();
try {
boolean found = false;
prepstmt = JVRConn.theConn.dbConn.prepareStatement
("SELECT BRR FROM LIAB WHERE TEXT = ?");
prepstmt.setString(1, specLiab);
ResultSet rs;
rs = prepstmt.executeQuery();
found = rs.next();
if (found)
System.out.println(rs.getString(1));
else
System.out.println("Not here" + specLiab + ");
prepstmt.close();
}
catch(Exception e ) {
e.printStackTrace();
}
}
}
This is my class to make the connection to my db. I know this is correct. I can't just put them together.
import java.net.URL;
import java.sql.*;
class JVRConn {
static myConnection theConn;
public static void main (String args[]) {
theConn = new myConnection();
theConn.Connect2Db("JVR", " ", " ");
}
}
class myConnection {
Connection dbConn = null;
void Connect2Db(String db, String user, String passw) {
try {
// using the driver
Driver d =
(Driver)Class.forName
("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
// URL corresponding to the ODBC DSN
String URL = "jdbc:odbc:" + db;
// DB logon
dbConn =
DriverManager.getConnection(URL, user, passw);
}
catch (Exception e) {
e.printStackTrace();
}
}
void Disconnect2Db() {
try {
dbConn.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
Courtney
ceaton@lrp.com