• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

passing the value obtained from DB

 
kenji kunoichi
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65123
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags.
 
Sherif Shehab
Ranch Hand
Posts: 485
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please can you put the sql exception ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic