wood burning stoves 2.0*
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
Author

passing the value obtained from DB

kenji kunoichi
Ranch Hand

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

public List getperInfoAll() {
int i = 0;
try
{

Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql","root","root");
ps = con.createStatement();
rs = ps.executeQuery("select * from userx");
while(rs.next())
{
System.out.println(rs.getString(1));
perInfoAll.add(i,new perInfo(rs.getString(1),rs.getString(2),rs.getString(3)));
i++;

}



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é
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

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
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

Please UseCodeTags.


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

Joined: Mar 05, 2007
Posts: 483

Please can you put the sql exception ?


Thanks,
Sherif
 
 
subject: passing the value obtained from DB
 
Similar Threads
Close JDialog without hide
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException
Problem with execAndWait interceptor
retrieving data from a databse into an excelsheet
dynamic JSF navigation