I currently have an sql string returned with the string wildcards marking null values. I am trying to find a way to set all of these wildcard values to null. After looking around, I have found a preparedStatement.setNull() method however it takes an index and the indexes of the wildcards will be subject to change. Is there a way to overcome this? (Example sql string given below):
String sqlCmd=
"INSERT INTO gs_support_structure (OBJECTID, gs_support_structure_gs_guid,
gs_support_structure_gs_vc_revision, gs_support_structure_gs_old_objectid,
gs_support_structure_gs_symbol_rotation, gs_support_structure_gs_subtype_cd,
gs_support_structure_gs_equipment_location, gs_support_structure_gs_map_no,
gs_support_structure_gs_substation, gs_support_structure_gs_description,
gs_support_structure_gs_height, gs_support_structure_gs_class,
gs_support_structure_gs_installation_date, gs_support_structure_gs_comments,
gs_support_structure_gs_date_created, gs_support_structure_gs_date_modified,
gs_support_structure_gs_diameter, gs_support_structure_gs_foundation_type,
gs_support_structure_gs_grounded, gs_support_structure_gs_manufacturer,
gs_support_structure_gs_material, gs_support_structure_gs_owner,
gs_support_structure_gs_pole_count, gs_support_structure_gs_style,
gs_support_structure_gs_treatment_type, gs_support_structure_gs_usage_type,
gs_support_structure_gs_old_layer_name,
gs_support_structure_gs_year_manufactured, gs_support_structure_gs_obj_no,
gs_support_structure_gs_prev_pole_id, gs_support_structure_gs_feeder_number,
gs_support_structure_gs_bec_substation,
gs_support_structure_gs_line_section, gs_support_structure_gs_facility_id,
gs_support_structure_gs_work_initiation_id,
gs_support_structure_gs_height_estimated,
gs_support_structure_gs_double_wood, gs_support_structure_gs_damaged,
gs_support_structure_gs_image_number, gs_support_structure_gs_x_coordinate,
gs_support_structure_gs_y_coordinate, gs_support_structure_gs_latitude,
gs_support_structure_gs_longitude, gs_support_structure_gs_gps_type,
gs_support_structure_gs_quality_value_meters,
gs_support_structure_gs_elevation_meters,
gs_support_structure_gs_construction_unit, gs_support_structure_gs_tag,
gs_support_structure_gs_tag_placed, gs_support_structure_gs_oldattachpole,
gs_support_structure_gs_poletopped, gs_support_structure_gs_polehazard,
gs_support_structure_gs_raptor, gs_support_structure_gs_groundpresent,
gs_support_structure_gs_test, gs_support_structure_gs_gpsdate,
gs_support_structure_gs_gpstime, gs_support_structure_gs_sriid,
gs_support_structure_gs_vc_modified_sw,
gs_support_structure_gs_ju_attached_fi,
gs_support_structure_gs_related_staking_guid,
gs_support_structure_gs_hyperlink, gs_display_feature_name, gs_guid) VALUES
('227', '{20731926-2A46-CDAC-547C-71226454977D}', '1099', '12202', '0.0',
'1', '1812', '571871874801', '9', ?, '40', '6', ?, ?, 'Thu Feb 25 17:25:19
CST 2010', 'Mon Feb 13 12:19:34 CST 2012', ?, ?, ?, ?, 'WOOD', 'BARTLETT',
?, ?, ?, 'PRI', ?, 'UNK', ?, ?, '03', 'Salty', ?, '1812', ?, 'Y', 'N', 'N',
?, '3293532.68888944', '1.021396693284668E7', '30.64895755', '-97.16239132',
?, ?, ?, ?, '106382', 'Y', 'N', 'N', 'NONE', 'NONE', 'Y', 'UNK', 'Fri Sep 04
00:00:00 CDT 2009', 'Sat Dec 30 10:24:13 CST 1899', '1812', ?, 'N', ?, ?,
'gs_support_structure', '{D63C9735-4632-7E71-726C-3248E8B25E44}')"
PreparedStatement preparedStatement =
spatialLiteConnection.prepareStatement(sqlCmd);
preparedStatement.execute();
JdbcUtil.close(preparedStatement);
I can just offer you to not use preparedStatement.setNull() in this case(so yours statements every time will be different and will take hard parse every time), but just replace all yours "?" to "NULL" inside your statement. Why not ?