Looking for method that projects variables into SQLibrary execute command.
in
Programming Questions
•
1 year ago
Hello,
This would be the example command to write to DB:
pgsql.execute(INSERT INTO table (column1, column2, etc) VALUES (value1, value2, ect));
For these variables:
String station_location_xml;
String observation_time_xml;
String temp_f_xml;
String temp_c_xml;
String relative_humidity_xml;
String wind_degrees_xml;
String wind_dir_xml;
String wind_mph_xml;
String wind_gust_mph_xml;
String dewpoint_f_xml;
String dewpoint_c_xml;
I want to write into the DB, which could look like:
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 + "')");
Except, the library requires a straight up string here for "VALUES".
I've tried coding:
String sqlCommand = new String ("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 + "')");
return (sqlCommand);
Then calling the variable:
pgsql.execute(sqlCommand);
However, I'm met with "
Exception in thread "Animation Thread" java.lang.NullPointerException".
This is a problem since this data is not static. How can I get the dynamic values into this string???
Is there a new method I can add to the source?
Thanks in advance!
1