File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes passing the value  obtained from DB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "passing the value  obtained from DB" Watch "passing the value  obtained from DB" New topic

passing the value obtained from DB

kenji kunoichi
Ranch Hand

Joined: Jun 02, 2007
Posts: 46
hi ,
I made a program which I first pull out values from database like this way :

public List getperInfoAll() {
int i = 0;

con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql","root","root");
ps = con.createStatement();
rs = ps.executeQuery("select * from userx");
perInfoAll.add(i,new perInfo(rs.getString(1),rs.getString(2),rs.getString(3)));


then in another funtion I want to use the value like :[/b]
public String sayHello() throws IOException,SQLException
getperInfoAll() ;
List abc = new ArrayList();

for(int i=0;i<2;i++)

abc.add(new Object[]{rs.getString(1),rs.getString(2),rs.getString(3)});

but I am getting an sqlexception...mainly because values are not going there... in abc.add so what error I am making? how to pass the ref there ?
Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

getperInfoAll is returning a List, isn't it ? (I hope your closing everything properly before returning the list) Shouldn't you use this returned value somewhere ?

[My Blog]
All roads lead to JavaRanch
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63868

Please UseCodeTags.

[Asking smart questions] [About Bear] [Books by Bear]
Sherif Shehab
Ranch Hand

Joined: Mar 05, 2007
Posts: 484

Please can you put the sql exception ?

I agree. Here's the link:
subject: passing the value obtained from DB
It's not a secret anymore!