[英]SQL query to Java String
我有一个简单的问题,但我找不到正确的方法。 When we use a query from SQL via Java we usually print the results in a JTable, my doubt it's ¿Is there a way to get that query into a Java String?
示例:我做了一个查询statement.executeQuery("SELECT Tiempo_elaboracion FROM catalogo_arreglos WHERE Id_arreglo='"+id_arre+"'");
结果是 00:07:00 ¿如何将该结果保存到 Java 字符串中?
我找到了一个额外的解决方案来补充,我为所有将来需要帮助的人发帖。
ResultSet myRS;
PreparedStatement myQuery
//Under this line "con" is the name of my connection//
myQuery = con.prepareStatement(SELECT value FROM table WHERE condition)
myRS = myQuery.executeQuery();
//The purpose is the save the value of the query into the String called "time"
if(myRS.next()){
String time = myRS.getString(1);
//The next line only print the String "time" for corroborate the procces//
System.out.println(""+time);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.