wsy
asked on
vector mysql question
hi
i have a method which takes in a String which is used to query the database, the results gets put into a Vector which is then return, the problem is i dont think the results are added in the Vector can someone help plz
public static Vector query(String query)
{
try{
stmt = con.createStatement();
rs = stmt.executeQuery("SELECT author,bookName, from book where author= ('"+ query+"') ");
while( rs.next() )
{
result.addElement(rs.getSt ring("auth or"));
result.addElement(rs.getSt ring("book Name"));
}
}catch (Exception e){System.out.println(e.ge tMessage() );}
return result;
}
i have a method which takes in a String which is used to query the database, the results gets put into a Vector which is then return, the problem is i dont think the results are added in the Vector can someone help plz
public static Vector query(String query)
{
try{
stmt = con.createStatement();
rs = stmt.executeQuery("SELECT author,bookName, from book where author= ('"+ query+"') ");
while( rs.next() )
{
result.addElement(rs.getSt
result.addElement(rs.getSt
}
}catch (Exception e){System.out.println(e.ge
return result;
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
e.g. get first author:
TableModel model = resultSetToTableModel(rs);
String firstAuthor = (String)model.getValueAt(1 , 0);
TableModel model = resultSetToTableModel(rs);
String firstAuthor = (String)model.getValueAt(1
ASKER
hi
thanks for the input i am going to try out your solution
i was wondering why didnt the code i wrote worked can some one explain?
thanks for the input i am going to try out your solution
i was wondering why didnt the code i wrote worked can some one explain?
Well you would have all the authors and bookNames on top of each other. You want them side by side logically - as in the table
yor are mixing both author and book with one collection. This becomes difficult to mage the values
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you can use the code as posted in above comment
The brackets in the sql are redundant btw and there are too many commas
Vector vect=query("SELECT author, bookName from book where author= '"+ query+ '");
Vector vect=query("SELECT author, bookName from book where author= '"+ query+ '");
yes, that's true ;-)
8-)
class Results
{
String author;
String bookname;
}
public static Vector query(String query)
{
try{
stmt = con.createStatement();
rs = stmt.executeQuery("SELECT author,bookName, from book where author= ('"+ query+"') ");
while( rs.next() )
{
Results r=new Results;
r.author=rs.getString("aut
r.book=rs.getString("bookN
result.addElement(r);
}
}catch (Exception e){System.out.println(e.ge
return result;
}