The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
April 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

SELECT Statement --- Vectors

Posted by Naveen on May 04, 2001 at 6:39 PM

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 WHERE = ? and = ?". 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 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





Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us