我在JDBC中使用mysql.
我有一个大型示例表,其中包含630万行,我正在尝试执行有效的选择查询.见下文:

执行这样的SELECT查询SELECT latitude, longitude FROM 3dag WHERE
timestamp BETWEEN "+startTime+" AND "+endTime+" AND HourOfDay=4 AND DayOfWeek=3"的运行时间非常高,为256356 ms,或略高于4分钟.我对同一个查询的解释给了我:

我检索数据的代码如下:
Connection con = null;
PreparedStatement pst = null;
Statement stmt = null;
ResultSet rs = null;
String url = "jdbc:mysql://xxx.xxx.xxx.xx:3306/testdb";
String user = "bigd";
String password = "XXXXX";
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(url, user, password);
String query = "SELECT latitude, longitude FROM 3dag WHERE timestamp BETWEEN "+startTime+" AND "+endTime+" AND HourOfDay=4 AND DayOfWeek=3";
stmt = …Run Code Online (Sandbox Code Playgroud) 我试图用JSON格式放两个int []和一个double []来通过我的java servlet发送.这就是我到目前为止所拥有的.
private JSONObject doStuff(double[] val, int[] col_idx, int[] row_ptr){
String a = JSONValue.toJSONString(val);
String b = JSONValue.toJSONString(col_idx);
String c = JSONValue.toJSONString(row_ptr);
JSONObject jo = new JSONObject();
jo.put("val",a)
jo.put("col",b);
jo.put("row",c);
return jo;
}
Run Code Online (Sandbox Code Playgroud)
但是当我打印JSONobject时,我得到了这个不可读的结果:
{"val":"[D@62ce3190","col":"[I@4f18179d","row":"[I@36b66cfc"}
Run Code Online (Sandbox Code Playgroud)
我在javascript中得到了相同的结果,我将JSONObject发送到.从数字到字符串的转换是否有问题?我应该使用JSONArray吗?
我想对大于或等于,小于或等于(我正在使用java btw)的字段执行查询.换一种说法.> =和<=.据我所知,mongoDB有$ gte和$ lte运算符,但我找不到合适的语法来使用它.我正在访问的字段是顶级字段.
我设法让这个工作:
FindIterable<Document> iterable = db.getCollection("1dag").find(new Document("timestamp", new Document("$gt", 1412204098)));
Run Code Online (Sandbox Code Playgroud)
还有...
FindIterable<Document> iterable = db.getCollection("1dag").find(new Document("timestamp", new Document("$lt", 1412204098)));
Run Code Online (Sandbox Code Playgroud)
但是你如何将这些相互结合呢?
目前我正在玩这样的声明,但它不起作用:
FindIterable<Document> iterable5 = db.getCollection("1dag").find(new Document( "timestamp", new Document("$gte", 1412204098).append("timestamp", new Document("$lte",1412204099))));
Run Code Online (Sandbox Code Playgroud)
有帮助吗?