ResultSet to Array/Vector
Does anyone have some code that read's data from a resultSet and puts it into a 3D array or Vector that I could look at? (3D array examples would be better).
The code I have is giving me a few problems and I was wondering how other people have implemented the above.
Try that buddy. this is similar taking it from an object and adding it to a vector and the only reason i am returning it cause i am using the vector in a jsp page...
public Vector getRecordE(String ProjectID){
ResultSet TPRO_E=null;
try{
PreparedStatement P_TPRO=conOrcl.prepareStatement("select * from recorde where PROJ_EXT_PROJ_ID=?");
//assign the ? to the argument passed
P_TPRO.setString(1,ProjectID);
//execute the statement
P_TPRO.execute();
//execute the query
TPRO_E= P_TPRO.executeQuery();
//looping through the resultSet
while (TPRO_E.next()){
//create an instance of the class
JavaBeans ItemE = new JavaBeans();
// set it to the Bean
ItemE.setTwinId(TPRO_E.getString("twin_proj_id"));
ItemE.setprojPhaseCode(TPRO_E.getString("proj_phase_cd"));
ItemE.setEfund_cd(TPRO_E.getString("fund_cd"));
//add the object to the vector
V_itemsE.addElement(ItemE);
}catch(SQLException w){
System.out.println(w.getMessage());
//returning the vector
return V_itemsE;
hope it helps... pretty close
Similar Messages
-
Why is conversion from array/vector of chars to jcharArray not working?
This really is an array/vector of chars, not a string (i.e. not a char* string).
jcharArray convert(JNIEnv* env, const std:vector<char> vect)
int size = vect.size();
jcharArray arr = env->NewCharArray( size );
env->SetCharArrayRegion( arr, 0, size, ( jchar * ) &( vect[ 0 ] ) );
return arr;
}It returns garble to Java instead of the characters put into the vector. What am I doing wrong?Presumably you have some reason to think that vect[ 0 ] is going to represent a contigous memory segement for the rest of the characters.
A java "char" and C "char" are not the same size. -
Converting a ResultSet to a Vector
hiya i gota question...(my code is below)...im doing a search query which searches the database for the search field and then these gets the results into a ResultSet.
i then need to print these out in a table kinda thing but at the moment the results are bunched together. this is a problem cos the <A HREF> link is highlighting all the results whereas each result needs to be linked to another page.
THEREFORE i think i need to convert the resultset to a vector and then print out the vector one by one onto the jsp page.
Enumeration enum = v.elements();
while(enum.hasMoreElements()) {
String s = (String) enum.nextElement();
query = "SELECT * FROM Login_Details LD, Personal_Details PD, Education E, Work_Experience WE, Skills S WHERE
LD.Email_Address = PD.Email_Address AND LD.Email_Address = E.Email_Address AND LD.Email_Address = WE.Email_Address AND
LD.Email_Address = S.Email_Address AND PD.Surname = '" + s + "'";
ResultSet rs = st.executeQuery(query);
while(rs.next()) {
%>
<%out.println(rs.getString("Surname")); out.println(", "); out.println(rs.getString("Forename"));%>
<%
any ideas ???
thanksHi
Try this
<TABLE border=1>
<%
while(rs.next()){%>
<TR>
<TD>
<%=rs.getString("Surname")+" "+rs.getString("Forename")%>
</TD>
</TR>
<%}%>
</TABLE>
Mars Amutha -
Storing resultset data to vector and then passing this data to JList
hi every body I am facing this problem since two days I tried but could't get correctly,I am new to java and I need to pass the result set data from the database to a JList having JCheckBox
I think I need to store the resulsetdata to a vector or array
I tried but could't solve the problem
I tried but could't get it
please do help me out
need some sample code for passing resultset data to JList having JCheckBox anybody please help me out
thanking you,
with regardshi guys any body please help me out
need a sample code for the first thread which i had the problems
trying but could't get that correctly,please please do help me out,
do help me out as I am new to java need some code snippet java gurus
thanking you,
with regards -
Array, Vector, or Hashtable?
I'm wondering what the best way to populate a names list for a chat program is. I need it to be able to set a unique identification to whoever joins the chat. It has to be able to tell who left, and be able to take just that persons name out of the list.
A Hashtable would let you match up user IDs to sockets, if that's your underlying design....
-
Putting Resultset objects in an Vector
Can anybody help me, I have to put all my results from the ResultSet in a Vector.
But I don't know how.
Thanx in advance.for a vector of vector ....
public static Vector prepareData(ResultSet rs)
Object lValue=null;
Vector returnedVector=new Vector();
try
Enumeration lEnum=null;
rs.beforeFirst();
while (!rs.isLast())
lEnum=this.elements();
Vector lLine=new Vector();
int i=0;
rs.next();
while (lEnum.hasMoreElements())
lValue=rs.getObject(i);
lLine.add(lValue);
i++;
returnedVector.add(lLine);
catch (SQLException e)
e.printStackTrace();
return returnedVector; -
Can you store the resultSet from a query into a vector?
I am totally frustrated. How the heck does one store the results of a query (resultSet) in a vector so that I can get the vector from my jsp page to display in a table.? searchRS is my resultSet from stmt.executeQuery().
public Vector storeResultSet ()throws SQLException
int dataType;
Vector rows = new Vector();
System.out.println("INSIDE SEARCHQUERY VALUE OF searchRS: " + searchRS);
// Get the ResultSetMetaData. This will be used for the column headings
ResultSetMetaData rsmd = searchRS.getMetaData();
// Get the number of columns in the result set
int numCols = rsmd.getColumnCount ();
columnNames = new String[numCols];
System.out.println("inside of store results and column count of rsmd is: " + numCols);
boolean more = searchRS.next();
while (more)
Vector testData = new Vector();
for(int i=0;i<numCols;i++)
Object value = searchRS.getObject(i);
rows.add(value);
System.out.println("VALUE of testData vector is: " + rows);
more = searchRS.next ();
rows.add(testData);
System.out.println("This is the populated vector in storeSearchResults " + rows);
return rows;
}>The OP has initiated a new thread asking this question, it's here
http://forum.java.sun.com/thread.jspa?threadID=5162925
Please don't created duplicate threads! If you feel you have to create a new thread for this question, post here and explain (as I did) so that no further replies will be posted to this thread. -
Size restrictions on arrays and vectors
Hi all!!!
I want to know whether there is any restriction on maximum size of array and vectors.
If I have thousands of records to be displayed on browser through JSP, can I initialise the arrays/vectors with that no.
Whether it will have adverse effect on performance.
Thanks in anticipationArray lists (and vectors) use an array as backing data store. And since array indices are ints, the maximum number of elements in an array list is Integer.MAX_VALUE (2 ^ 31 - 1).
About the performance: if you know how many elements you are going to add (albeit not precisely), you can create the array list with an initial capacity. This will improve performance because a new array is created when an element is to be added but the capacity has been reached.
Kind regards,
Levi -
Can Vector contain ResultSet which is a Interface
What i am trying is to execute 3 different SQL in a Bean and try it to transfer in a JSP.I am using Vector for this work.I am putting the ResultSet in the Vector and transfer that Vector to the Jsp,In which i am displaying the Result.
I wanted to know that Is it possible to do the thing in this way.Or some other way is there.
Could any one tell me the Solution.May be I 'm wrong, but the objets implementing the ResultSet interface
must be serializable and have a public default constructor if you want
to serialize/deserialize them. I don't think the most know drivers
are offering you these features.
Even if it's feasible, I don't think serializing a whole data set is
really a good idea, because of the big overhead of doing this.
You'd better convert the resultSet into smaller objects and
only pass a set of them to your jsp only under request,
not the whole thing once.
Hope this helps -
Add Vector or ResultSet to JComboBox
My program retrives a list of table (names) from a database, when a get_table Jbutton is clicked.
The JComboBox has already being instantiate with the rest of GUI component (in the JFlame constructor).
However do I pass a Vector or rather a ResultSet of table names to the JComboBox ? It would have been easy to pass in a Vector to JComboBox constructor, but the list of items to fill in was un-determine yet (by the users).My program retrives a list of table (names) from a
database, when a get_table Jbutton is clicked.
The JComboBox has already being instantiate with the
rest of GUI component (in the JFlame constructor).
However do I pass a Vector or rather a ResultSet of
table names to the JComboBox ? It would have been
easy to pass in a Vector to JComboBox constructor, but
the list of items to fill in was un-determine yet (by
the users).you can't. once the JComboBox has been instantiated, it's there. instead, cycle through your resultSet or your vector. Here's some
code:
<pre>
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.PopupMenuListener;
import javax.swing.event.PopupMenuEvent;
import java.util.Vector;
public class TestDynamicComboBox extends JDialog {
private JComboBox jComboBox1 = new JComboBox();
public TestDynamicComboBox() {
jComboBox1.addItem("one value");
JButton change = new JButton("get_table");
change.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
// assume you're vector has been filled otherwise...
Vector vec = new Vector();
vec.add("one of three");
vec.add("two of three");
vec.add("three of three");
jComboBox1.removeAllItems(); // just in case...
for (int i=0; i<vec.size(); i++) {
jComboBox1.addItem((String)vec.elementAt(i));
JPanel test = new JPanel(new FlowLayout(FlowLayout.CENTER));
test.add(jComboBox1);
test.add(change);
this.getContentPane().add(test, BorderLayout.CENTER);
public static void main(String[] args) {
TestDynamicComboBox test = new TestDynamicComboBox();
test.pack();
test.show();
</pre>
peace. JOe... -
hi,
ok my problem is i am trying to create a vector object in jbuilder with this
private Vector<Object> rows;
but i keep getting a error saying generics are not supported in 1.2 try -source 1.5.
how can i create a vector object in 1.2, i am seriously stuck can you please help.
regardsi now got the 1.5 to work without the invocation errors, the whole reason i needed the array is as such
setting array
Vector<Object> rows;
then
public void setauctiondetails() throws java.rmi.RemoteException {
Connection link = null;
Statement statement = null;
ResultSet results = null;
Class.forName(
"sun.jdbc.odbc.JdbcOdbcDriver");
link = DriverManager.getConnection(
"jdbc:odbc:auction","","");
statement = link.createStatement();
results = statement.executeQuery(
"SELECT * FROM auctiondetails");
rows = new Vector<Object>();
while (results.next())
rows.addElement(results.getInt(1));
rows.addElement(results.getString(2));
rows.addElement(results.getString(3));
rows.addElement((results.getInt(4)));
link.close();
for(int i=0; i<clients.size(); i++){
icl = (Iclient)clients.get(i);
icl.updateTime(rows);
but still getting a error with the bloody array saying "type java.util.vector does not take parameters". i no you guys are really good at java, so tried not to have a go just need to be pointed to a tutorial or some code that might explain this better to me.
kind regards -
Hi Everybody,
Can anybody tell me is there any method to compare the contents of two ResultSets and decide whether they are same or not.
ThanksYes,
Create a method that takes the two result sets, get the metada of the table and compare field by fiel.
Another alternative is to copy the ResultSet to a Vector and than compare it.
HTH
Trajano Roberto -
ResultSet from Java Stored Procedures
Hi,
How do I obtain a resultset from a Java Stored Procedure?
My stored procedure, deployed in Oracle8i, has Database package as sample.Have published setConnection() and getDept() methods.
Code for Java Stored Procedure:
package SPPackage;
import java.sql.*;
public class StoredProcApplication {
protected static Connection connection = null;
protected static Statement stmt = null;
protected static ResultSet res = null;
public static void setConnection() throws SQLException {
connection = new oracle.jdbc.driver.OracleDriver().defaultConnection();
public static void getDept(Object[] obj) throws SQLException {
if (connection == null) {
setConnection();
if (stmt == null) {
stmt = connection.createStatement();
if (res == null) {
res = stmt.executeQuery("select * from DEPT");
obj[0] = res;
Code for TesterApplication :
package SPPackage;
import java.sql.*;
public class TesterApplication {
private static final String URL = "jdbc:oracle:thin:@sandeep:1521:oracle8i";
private static final String userId = "sandeep";
private static final String password = "sandeep";
private Connection connection;
private CallableStatement stmt;
private ResultSet res;
public void setConnection() throws ClassNotFoundException,SQLException {
Class.forName("oracle.jdbc.driver.OracleDriver");
connection = DriverManager.getConnection(URL,userId,password);
public void getResultFromSP() throws SQLException {
//prepare to call the stored procedure
stmt = connection.prepareCall("{call sample.getDept(?)}");
//register the OUT parameters
stmt.registerOutParameter(1,Types.OTHER);
//execute the query
stmt.execute();
ResultSet res = (ResultSet)stmt.getObject(1);
while (res.next()) {
System.out.print(res.getInt(1) + " | " );
System.out.print(res.getString(2) + " | " );
System.out.print(res.getString(3) + " \n " );
public TesterApplication() throws SQLException,ClassNotFoundException {
try {
setConnection();
getResultFromSP();
} finally {
if (res != null) { res.close(); res = null; }
if (stmt != null) { stmt.close(); stmt = null; }
if (connection != null) { connection.close(); connection = null; }
public static void main(String[] args) {
try {
TesterApplication ta = new TesterApplication();
} catch (Exception e) {
System.err.println("Error while executing stored procedure " + e.getMessage());
e.printStackTrace();
When I run the TesterApplication, I get the following exception :
java.sql.SQLException: Invalid column type: get_internal_type
at oracle.jdbc.dbaccess.DBError.check_error(Compiled Code)
at oracle.jdbc.driver.OracleStatement.get_internal_type(Compiled Code)
at oracle.jdbc.driver.OracleCallableStatement.registerOutParameter(Compiled Code)
Also, if I want to execute the ResultSet in the stored proc itself, and return the values as Arrays of int[], and String[], how do I do it?By default the you can populate only int[0], String[0] , i.e. only one value!!!
if my statement is unknown, i.e, it might return a combination of updates and resultsets, how do I go about processing the result?
Please advise!!
TIA
Sandeep
nullHi kkirk,
I found the post you mentioned.Well it dates back to November 1999 - "Problem returning resultset or ARRAY from java stored proc" by Stuart Popejoy ([email protected]).Too bad, it is still not solved!!
I am not very good at PL/SQL.However, it would still be helpful, if you could post the code here, or at my email address.
Meanwhile, I was trying this during the week-end.There seems to be a glimmer of hope!!
Let me know, if this makes sense :
CallableStatement cs = connection.prepareCall("begin open ? for select * from dept; end");
try {
cs.registerOutParameter(1,OracleTypes.CURSOR);
ResultSet res = ((OracleCallableStatement)cs).getCursor(1);
while (res.next()) {
//get the values
} catch (Exception e) {
e.printStacktrace();
However, I am getting an exception trace
Error while executing stored procedure Invalid column type: getLong
java.sql.SQLException: Invalid column type: getLong
at oracle.jdbc.dbaccess.DBError.check_error(Compiled Code)
at oracle.jdbc.driver.OracleStatement.getLongValue(Compiled Code)
Not quite sure why this is happening!!
TIA,
Sandeep
null -
JDBC:Count Array. SQL query works but fails in JDBC
Hi,
I'm using the following SQL query
"SELECT red.id, name, count(green.id) FROM red, green WHERE area = 'northeast' AND red.id = zid GROUP BY name"
It executes perfectly from the DB command line giving me the results.
However when I call it from within JDBC i am getting null values.
My JDBC call ia as follows( Where lst is the above query)
rs = st.executeQuery(lst);
while(rs.next()){
nidV.addElement(rs.getString("red.id"));
nnmV.addElement(rs.getString("name"));
nnumV.addElement(rs.getString("count(green.id)"));
I do realize that many folks use Integer for count queries but I pull them with as Strings all the time so that's not it.
The one diffrence between this and my other count queries is that this one returns an array (Vector) of counts.
Any ideas?the problem is probably:
SELECT red.id, name, count(green.id) ...
nnumV.addElement(rs.getString("count(green.id)"));you can either use an alias for the column;
SELECT red.id, name, count(green.id) COUNT_VAR
nnumV.addElement(rs.getObject("COUNT_VAR"));or use getObject(3) as suggested by drclap. -
Does anyone know how to put v_array1D into a hashtable??
I must also be able to get it as an array of String
Hashtable v_array2D=null;
String[] v_array1D=new String[c_colsize];
while (rs.next()){
row_exist=true;
for (int j=0;j<c_colsize;j++){ //I selected 6 rows from above
System.out.print(rs.getString(j+1)+" ");
v_array1D[j]=rs.getString(j+1);//getString starts from index 1 for column 1
v_array2D.put(new Integer(i),v_array1D);//create a 2D array, but not successful
i++;
}//end of resultset, 2D array createdBeside you have not instansiate the Hashtable v_array2D, it should work otherwise.
How do you get the array back? Like this:
String[] sa = (String[]) v_array2D.get(new Integer(i));
--lichu
Maybe you are looking for
-
I have a 2 Giga Creative Zen since 4 months. I used it without any difficulty until about 3 weeks ago, when I discoverd I couldn't switch it on anymore.... and if I connect (USB) it to my notebook it only happens that the screen has some kind of flas
-
BT Widget YVM105 Problem unable to use
Hiya there Brand new YV user here I've set up the YV box and almost everything works really well, except The BT widget (the BT on the on demand section to access BT films etc.) now I have both an e-mail and phone confimation that it is et up but when
-
How do I create a booklet in pages?
Hi I want to do an order of servie for a wedding - which is on Saturdsy - and I need to get it printed as a booklet. I can't see how to do this in Pages. Thanks in advance for your help. Elaine
-
Ipod nano replacement program, box, 10 days to respond etc
When I called this morning Apple said they ran out of boxes, that more boxes will go out when they get more, and that the 10-day period one has to return the ipod before the "service" request is cancelled does not begin until the box is received.
-
IWeb not launching...freezes
Hopefully someone can point me in the right direction here. Last night, I was working on iWeb just fine...put up a blog post. This morning, when I tried to launch iWeb, it starts to load (two of the windows open), but the main work area window does n