Guest_imported
New member
- Jan 1, 1970
- 0
I am trying to create a SelectComponent class for selecting data from Maintenance Tables. This class will be used for all the tables. I am trying to use vector objects. But, I am not sure how to do this. The constructor in the code below should take sql statements of the form: Example: "SELECT * FROM TABLENAME WHERE FIELDNAME= ? and FIELDNAME= ?". And, the following code has a few errors too.
Code:
import java.io.*;
import java.sql.*;
import java.util.*;
public class SelectComponent {
private int rowCount;
private int columnCount;
private int currentRow;
private Statement stmt;
private ResultSet rs;
}
/**
Insert the method's description here.
Creation date: (5/2/01 10:24:34 AM)
@param c java.sql.Connection
@param sql java.lang.String
@param input java.lang.String
/
//String input is what the users enter on the screen
public SelectComponent(Connection c, String sql, String input) {
try {
java.util.Vector v = new java.util.Vector();
PreparedStatement p = c.prepareCall(sql);
v.addElement();
for (int i=0; i < v.size(); i++) {
Object o = v.elementAt(i);
if (o instanceof integer) {
p.setInt();
}
else if (o instanceof String) {
p.setString();
}
else if (o instanceof Double) {
p.setDouble();
}
}
}
catch (Exception e) {
e.printStackTrace();
}
}
If I am working with a particular table and its values then I will type in something like this:
"SELECT * FROM ISPROJ WHERE Proj = ? and dept = ? and Cost_Center = ?";
java.util.Vector v = new java.util.Vector();
v.addElement (new Integer (Proj));
v.addElement (dept);
v.addElement (new Double (Cost_Center);
and so on...
But, how do I do it for multiple tables and values???
I will greatly appreciate any help.
Thanks,
Naveen
Code:
import java.io.*;
import java.sql.*;
import java.util.*;
public class SelectComponent {
private int rowCount;
private int columnCount;
private int currentRow;
private Statement stmt;
private ResultSet rs;
}
/**
Insert the method's description here.
Creation date: (5/2/01 10:24:34 AM)
@param c java.sql.Connection
@param sql java.lang.String
@param input java.lang.String
/
//String input is what the users enter on the screen
public SelectComponent(Connection c, String sql, String input) {
try {
java.util.Vector v = new java.util.Vector();
PreparedStatement p = c.prepareCall(sql);
v.addElement();
for (int i=0; i < v.size(); i++) {
Object o = v.elementAt(i);
if (o instanceof integer) {
p.setInt();
}
else if (o instanceof String) {
p.setString();
}
else if (o instanceof Double) {
p.setDouble();
}
}
}
catch (Exception e) {
e.printStackTrace();
}
}
If I am working with a particular table and its values then I will type in something like this:
"SELECT * FROM ISPROJ WHERE Proj = ? and dept = ? and Cost_Center = ?";
java.util.Vector v = new java.util.Vector();
v.addElement (new Integer (Proj));
v.addElement (dept);
v.addElement (new Double (Cost_Center);
and so on...
But, how do I do it for multiple tables and values???
I will greatly appreciate any help.
Thanks,
Naveen