如何实现收件人对派送信息的查询,以及快递状态的改变?

CSDN问答 2021-12-30 11:27:39 阅读数:370

实现 收件 送信 收件人 派送

package query;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;public class Query { public static void main(String[] args) throws SQLException { // TODO 自动生成的方法存根 Connection connection = null; Statement statement; ResultSet rs; try { Class.forName("com.mysql.jdbc.Driver"); }catch (Exception e) { System.out.print(e); } String url = "jdbc:mysql://localhost:3306/express"; String user = "root"; String password = "root"; try { connection = DriverManager.getConnection(url,user,password); }catch (Exception e) { System.out.print(e); } statement = (Statement) connection.createStatement(); rs = ( ( java.sql.Statement ) statement).executeQuery("select id,sname,state from express"); while(rs.next()) { String id = rs.getString(1); String sname = rs.getString(5); String state = rs.getString(6); System.out.println("派送信息:id:" + id + "派送员" + sname + "派送状态" + state); } rs.close(); statement.close(); connection.close(); }}



采纳答案:

查询,修改。。
getString()是取查询结果的值,不是表中字段对应的索引,所以你直接取1,2,3

String id = rs.getString(1);String sname = rs.getString(2);String state = rs.getString(3);

版权声明:本文为[CSDN问答]所创,转载请带上原文链接,感谢。 https://ask.csdn.net/questions/7619893