aspose file tools
The moose likes Beginning Java and the fly likes passing the value  obtained from DB Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Reply 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: 39
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: 14685
    
  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: 56529
    
  14

Please UseCodeTags.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Sherif Shehab
Ranch Hand

Joined: Mar 05, 2007
Posts: 472

Please can you put the sql exception ?


Thanks,
Sherif
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: passing the value obtained from DB
 
Similar Threads
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException
dynamic JSF navigation
retrieving data from a databse into an excelsheet
Problem with execAndWait interceptor
Close JDialog without hide