We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I am trying to retrieve one value from a sql table, but I keep running into an error that states that I have not made a query. Though I thought I did. I am trying to submit an iterative query that reads one row in a specific column at a time that feeds into the getFloat function.
import de.bezier.data.sql.*;
int r;
PostgreSQL pgsql;
float database () {
String user = "";
String pass = "";
// name of the database to use
//
String database = "db";
// connect to database on "localhost"
//
pgsql = new PostgreSQL( this, "127.0.0.1", database, user, pass );
// connected?
//connect to database
if ( pgsql.connect() )
{
//class submits query for a column, but the console reads that 'I need to query() something first for the getFloat("co2")'
pgsql.query(( " SELECT ROW_NUMBER (" + str(r) + ") AS co2 FROM tree"));
//iterate r
r++;
return( pgsql.getFloat("co2") );
}
else
{
//disconnect from database
}
return(0);
}
Answers
Are you sure of the SQL request syntax?
How this problem is related to your topic subject?
Why do you make near duplicate threads?
Why do you put double parentheses in the query() call? (Not a real problem, just curious...)
I am trying to be sure of the syntax...
you might suggest another query.
Anyways, the pgSQL table provides data for a visualization in Processing via the bezier class. The visualization updates at regular time intervals with a singular data point, rather than an entire column or row.
I am making near duplicate threads because 1) newbie to programming (sorry PhiLho), 2) this is the final small bug that connects a simulated Pi to Amazon pgSQL database to Processing (I would like to get success), and 3) the project was bigger than my knowledge. I am a proverbial programming test crash dummy trying to integrate python, processing, and SQL simultaneously within 2 weeks.
I would have deleted the previous threads if I had that ability.
To answer the last question, a typo in the multiple syntax changes that have occurred in the last several attempts to try to get it right.
thanks for the link. its the first real useful thing i have read.
ok, the query syntax is now fine, but here is the thing I don't comprehend. I follow all of the structures I have seen on the web for this and even though the code connects, has a query in the program, the processing console returns this mess that states java errors.... like 7 of them and that I need to submit a query. pgsql.query is making the call, but it is not receiving the query. It reads "You need to query() something first." Have I not done that in this code?
Better paste here this "mess that states java errors", we are used to interpret it.
Here are the errors.
hereSQL.query(): java.sql.SQLException.
// I am not sure where this came from. I do not use this line of code.
//I use this followinf line of code that works in the command line of the pgSQL database
Perhaps
table
is a reserved word? Better use another name for your table.Not sure about the first one, but it might be related (looks like an internal request failing somewhere).
A person on stack exchange I think nailed it. The errors are caused by moving the code from within the setup function to a helper file, which that migration is what I am trying to accomplish. I don't fully understand it, but it is related to the extension of the Papplet in the Java base... maybe it is just finnicky?
So the code has improved bc of the observations from others. I can't get to the point of getting the code to work because the IDE reports a token error in the class Database.
"Class Database"
Java (and Processing) is case-sensitive. Must be
class Database
.The
col;
statement is useless / nonsensical too. So isreturn float (col = 0);
There is no field named col, only a constructor parameter.