dcsimg
How to get data from a database
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   david_kelly
Posted On:   Friday, May 4, 2007 03:52 AM

Guys, thanks very much for your invaluable help. I got my database to store perfectly with the prepared statement. Now I am wanting to find some data. Ok, I know you just do the query "SELECT * FROM "+tableName+" WHERE column_1 = '"+date+"'" this gives me everything but I want to store each columns value to a specific variable, so that I can send this to another class for display purposes. I wanted to iterate this to make it easier, this is what I have so far in a try and catch: con = DriverManager.getConnection(dbURL, "",""); s = con.createStatement(); s.execute("SELECT * FROM    More>>

Guys, thanks very much for your invaluable help.



I got my database to store perfectly with the prepared statement.

Now I am wanting to find some data.



Ok, I know you just do the query "SELECT * FROM "+tableName+" WHERE column_1 = '"+date+"'" this gives me everything



but I want to store each columns value to a specific variable, so that I can send this to another class for display purposes.



I wanted to iterate this to make it easier, this is what I have so far in a try and catch:

			
con = DriverManager.getConnection(dbURL, "","");
s = con.createStatement();
s.execute("SELECT * FROM "+tableName+" WHERE column_1 = '"+date+"'");
ResultSet rs = s.getResultSet(); // get any ResultSet that came from our query
boolean found = rs.next();
if (rs != null)
{
if(!found)
{
System.out.println("Nothing Found");
} //close if
else
{
for(int i = 0; i <= 11; i++)
{
int j=i+2;
stringData ps.setString("SELECT column_'"+j+"' FROM "+tableName+" WHERE column_1 = '"+date"'");
getData[i] = stringData;
}
for(int j = 0; j <= 4; j++)
{
//same as above but start at column_14 and save different primatives
}
}//close else
} //close if

but i get errors, not surprising since SQL is something I still need to fully learn. I think the prepared statement, is the wrong way to go, I was looking into the ResultSet but I cant seem to get this to work either.e.g.

String stringData = rs.getNString("column_2");

how can I get the data from the database?


davy

   <<Less

Re: How to get data from a database

Posted By:   david_kelly  
Posted On:   Friday, May 4, 2007 08:51 AM

I even tried:

s.execute("SELECT * FROM "+tableName+" WHERE column_1 = '"+date+"'");
ResultSet rs = s.getResultSet(); // get any ResultSet that came from our query
boolean found = rs.next();
if (rs != null) // if rs == null, then there is no ResultSet to view
{
for(int i = 0; i <= 11; i++)
{
int x=i+2;
stringData = rs.getString(x);
getAppsData[x] = stringData;
bs.gotTheString[x] = getAppsData[x];
System.out.println(getAppsData[x]);
}
for(int j = 0; j <= 4; j++)
{
//same as above

}
same as above for column_19
} //close if


davy
About | Sitemap | Contact