aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/database/ResultSetConverter.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/database/ResultSetConverter.java')
-rw-r--r--src/org/traccar/database/ResultSetConverter.java42
1 files changed, 23 insertions, 19 deletions
diff --git a/src/org/traccar/database/ResultSetConverter.java b/src/org/traccar/database/ResultSetConverter.java
index 32289f756..e4aec956c 100644
--- a/src/org/traccar/database/ResultSetConverter.java
+++ b/src/org/traccar/database/ResultSetConverter.java
@@ -15,24 +15,29 @@
*/
package org.traccar.database;
-import org.json.JSONArray;
-import org.json.JSONObject;
-
-import java.sql.SQLException;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import javax.json.Json;
+import javax.json.JsonArray;
+import javax.json.JsonArrayBuilder;
+import javax.json.JsonObjectBuilder;
public class ResultSetConverter {
+
+ private static final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ssZ");
- public static JSONArray convert(ResultSet rs) throws SQLException {
+ public static JsonArray convert(ResultSet rs) throws SQLException {
- JSONArray json = new JSONArray();
+ JsonArrayBuilder json = Json.createArrayBuilder();
ResultSetMetaData rsmd = rs.getMetaData();
while (rs.next()) {
int numColumns = rsmd.getColumnCount();
- JSONObject obj = new JSONObject();
+ JsonObjectBuilder obj = Json.createObjectBuilder();
for (int i = 1; i <= numColumns; i++) {
@@ -40,41 +45,40 @@ public class ResultSetConverter {
switch (rsmd.getColumnType(i)) {
case java.sql.Types.BIGINT:
- obj.put(columnName, rs.getInt(columnName));
+ obj.add(columnName, rs.getInt(columnName));
break;
case java.sql.Types.BOOLEAN:
- obj.put(columnName, rs.getBoolean(columnName));
+ obj.add(columnName, rs.getBoolean(columnName));
break;
case java.sql.Types.DOUBLE:
- obj.put(columnName, rs.getDouble(columnName));
+ obj.add(columnName, rs.getDouble(columnName));
break;
case java.sql.Types.FLOAT:
- obj.put(columnName, rs.getFloat(columnName));
+ obj.add(columnName, rs.getFloat(columnName));
break;
case java.sql.Types.INTEGER:
- obj.put(columnName, rs.getInt(columnName));
+ obj.add(columnName, rs.getInt(columnName));
break;
case java.sql.Types.NVARCHAR:
- obj.put(columnName, rs.getNString(columnName));
+ obj.add(columnName, rs.getNString(columnName));
break;
case java.sql.Types.VARCHAR:
- obj.put(columnName, rs.getString(columnName));
+ obj.add(columnName, rs.getString(columnName));
break;
case java.sql.Types.DATE:
- obj.put(columnName, rs.getDate(columnName));
+ obj.add(columnName, dateFormat.format(rs.getDate(columnName)));
break;
case java.sql.Types.TIMESTAMP:
- obj.put(columnName, rs.getTimestamp(columnName));
+ obj.add(columnName, dateFormat.format(rs.getTimestamp(columnName)));
break;
default:
- obj.put(columnName, rs.getObject(columnName));
break;
}
}
- json.put(obj);
+ json.add(obj.build());
}
- return json;
+ return json.build();
}
}