Java - Getting Data from MySQL database

前端 未结 6 482
南笙
南笙 2021-02-04 15:31

I\'ve connected to a MySQL database, which contains four fields (the first of which being an ID, the latter ones each containing varchar strings).

I am trying to get the

6条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-04 16:11

    This should work, I think...

    ResultSet results = st.executeQuery(sql);
    
    if(results.next()) { //there is a row
     int id = results.getInt(1); //ID if its 1st column
     String str1 = results.getString(2);
     ...
    }
    

提交回复
热议问题