我有 java 代码,它使用 netbeans 中的适当代码从 MySQL 检索一些数据。代码如下。我想做多查询,例如查找产品总数等等。请你帮帮我。提前致谢
import java.sql.*;
public class JavaMysqlSelectExample
{
public static void main(String[] args)
{
try
{
String myDriver = "com.mysql.jdbc.Driver";
String myUrl = "jdbc:mysql://localhost/sample";
Class.forName(myDriver);
Connection conn = DriverManager.getConnection(myUrl, "root", "mypasscode1");
String query = "SELECT * FROM products";
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(query);
while (rs.next()==true)
{
int code = rs.getInt("code");
String productname = rs.getString("product_name");
String producttype = rs.getString("product_type");
System.out.format(" %d, %s, %s\n", code, productname, producttype);
}
st.close();
}
catch (Exception e)
{
System.err.println("Error message: ");
System.err.println(e.getMessage());
}
} }