gpt4 book ai didi

java-mysql程序

转载 作者:行者123 更新时间:2023-11-30 09:52:32 26 4
gpt4 key购买 nike

我有一个表 - mysql 中的 emp_details我想在 java 中查找雇员的 ID 号。如果在表中,则显示员工的所有详细信息。否则显示错误信息。我是怎么做到的

最佳答案

Using JDBC
这是一个示例,您可以从中构建您的解决方案。

   Statement stmt = null;
String query = "select COF_NAME, SUP_ID, PRICE, SALES, TOTAL from " + dbName + ".COFFEES";
try {
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
String coffeeName = rs.getString("COF_NAME");
int supplierID = rs.getInt("SUP_ID");
float price = rs.getFloat("PRICE");
int sales = rs.getInt("SALES");
int total = rs.getInt("TOTAL");
System.out.println(coffeeName + "\t" + supplierID + "\t" + price + "\t" + sales + "\t" + total);
}
} catch (SQLException e ) {
JDBCTutorialUtilities.printSQLException(e);
} finally {
stmt.close();
}

关于java-mysql程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4212814/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com