【发布时间】:2015-05-25 19:35:46
【问题描述】:
我有问题。
我的 java 程序中有一个字符串数组。 在我的数据库中,我也有字符串,但是 它们在以太列 a 或 b 列中。我需要 在我的 java 程序中知道我的元素是否 数组是元素 a 或元素 b。我善良 对如何执行此操作感到困惑。
我有 mysql 连接,查询工作正常,没有问题。
当前的java类是:
public static String getCountedDatesTypes(String check) throws ClassNotFoundException {
String wholeDataModel = "";
String dates;
String myDriver = "org.mariadb.jdbc.Driver";
Class.forName(myDriver);
Connection con = null;
Statement st = null;
ResultSet rs = null;
String url = "jdbc:mariadb://localhost:3306/house";
String user = "root";
String password = "supermanspassword";
try {
String tmpblack = "";
String tmpnormal = "";
String tmpcheap = "";
con = DriverManager.getConnection(url, user, password);
st = con.createStatement();
String sqlQuery = String.format("select count(black) as black,count(normal) as normal ,count(cheap) as cheap from dates;");
rs = st.executeQuery(sqlQuery);
while (rs.next()) {
String b = rs.getString("black");
String n = rs.getString("normal");
String c = rs.getString("cheap");
System.out.println(b + " " + n + " " + c);
}
} catch (SQLException ex) {
Logger lgr = Logger.getLogger(Mysql_interaction.class.getName());
lgr.log(Level.SEVERE, ex.getMessage(), ex);
} finally {
try {
if (rs != null) {
rs.close();
}
if (st != null) {
st.close();
}
if (con != null) {
con.close();
}
} catch (SQLException ex) {
Logger lgr = Logger.getLogger(Mysql_interaction.class.getName());
lgr.log(Level.WARNING, ex.getMessage(), ex);
}
}
数据库(超级简单):
MariaDB [house]> select * from dates;
+----------+----------+----------+
| black | normal | cheap |
+----------+----------+----------+
| 5/5/2015 | NULL | NULL |
| NULL | 6/5/2015 | NULL |
| NULL | NULL | 7/5/2015 |
| NULL | NULL | 8/5/2015 |
+----------+----------+----------+
我需要计算我在 java 类中的数组中选定日期的价格。我需要知道有多少 normal 和 ceap 。因此,如果提供了 2015 年 6 月 5 日和 2015 年 8 月 5 日的日期,我需要能够知道这是 1 正常和 1 便宜。
字符串检查应该是稍后工作时的字符串类型数组。
谁能帮我解决这个问题。
问候, 瑞克
【问题讨论】:
-
你能澄清你的问题吗?请发布您现在拥有的代码,并解释它如何不能满足您的要求。
-
我晚上会澄清这个问题,请稍候。