经过[http://stackoverflow.com/users/1690199/v-k]的仔细观察后,我改进了结构,尽管语法对我来说仍然正确,但仍然出现令牌错误。更多的评论和评论将在这里有用并得到认可。
import de.bezier.data.sql.*;
PostgreSQL pgsql;
Float val;
void setup()
{
size( 100, 100 );
println(val);
}
在类数据库的处理2中标识的令牌错误。
Class Database
{
String user = "user";
String pass = "pass";
String database = "db";
Float val;
Database (Float col) {
val = col;
}
void database_connection( col )
{
//sets up database
pgsql = new PostgreSQL( this, "127.0.0.1", database, user, pass );
if ( pgsql.connect() )
{
pgsql.query( "SELECT col FROM table ORDER BY col DESC LIMIT 1; " );
return( pgsql.getFloat("col") );
}
else
{
println ("failed to connect to the database");
}
}
}
旧问题:[http://stackoverflow.com/users/1690199/v-k]进行了详尽的观察后,解决了类结构
导入de.bezier.data.sql。*;
.....
.....
为清楚起见,已删除旧代码。
最佳答案
类不带参数。也是班级而不是班级...我错过了什么吗?看,一般样本:
class Database {
String user = "user";
String pass = "pass";
String database = "db";
float val; //by convention no Caps for vars...
// a constructor, which get partameters
Database (float v) {
val = v;
}
// a method
void database_setup() {
//whateverq
}
}//end of Database class