Can a DB be manipulated with SQLibrary?
in
Programming Questions
•
1 year ago
I would like to write data to my PostgreSQL DB using SQLibrary.
First off, is it capable of doing that? I've had success querying the DB using this library, but there doesn't seem to be much documentation on writing to a DB using it. I've tried using pgsql.execute but get this error:
SQL.query(): java.sql.SQLException.
org.postgresql.util.PSQLException: ERROR: syntax error at end of input
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1608)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1343)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:194)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:451)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:336)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:328)
at de.bezier.data.sql.SQL.execute(Unknown Source)
at dbQuery_XMLFeed.manipulateDB(dbQuery_XMLFeed.java:234)
at dbQuery_XMLFeed.draw(dbQuery_XMLFeed.java:56)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:662)
The fact that it says "SQL.query():" leads me to think that this library only queries.
If it is possible, could someone provide an example?
Thanks in advance.
void manipulateDB(){
//query write start
size( 300, 300 );
// assumes that you are running the
// postgresql server locally (on "localhost").
//
// replace with your own postgresql-account.
//
String user = "user name";
String pass = "password";
// name of the database to use
//
String database = "db name";
// connect to database on "localhost"
//
pgsql = new PostgreSQL( this, "db address", database, user, pass );
// connected?
if ( pgsql.connect() )
{
pgsql.execute( "INSERT INTO adaptive_weather_longterm (station_location, observation_time, temp_f, temp_c, relative_humidity, wind_dir, wind_mph, wind_gust_mph, dewpoint_f, dewpoint_c) VALUES (station_location_xml, observation_time_xml, temp_f_xml, temp_c_xml, relative_humidity_xml, wind_dir_xml, wind_mph_xml, wind_gust_mph_xml, dewpoint_f_xml, dewpoint_c_xml");
}
else
{
//connection failed !
}
//query write end
}
1