getString(int columnIndex)
引數說明:Connection conn = …… //省略部分程式碼 String sql = "SELECT username,pwd FROM myTable"; //定義查詢SQL語句 Statement st = conn.createStatement(); ResultSet rs = st.executeQuery(sql); while(rs.next()){ System.out.println(rs.getString(1)); //獲取資料表中第一列資料值 System.out.println(rs.getString(2)); //獲取資料表中第二列資料值 }
getString(String columnLabel))
引數說明:Connection conn = …… //省略部分程式碼 String sql = "SELECT username,pwd FROM myTable"; Statement st = conn.createStatement(); ResultSet rs = st.executeQuery(sql); while(rs.next()){ System.out.println(rs.getString("username")); //獲取username列的列值 System.out.println(rs.getString("pwd")); //獲取pwd列的列值 }