我正在尝试从数据库中获取一些数据并尝试使用简单的数组列表概念显示相同的数据。但我没有得到预期的数据。请帮助我错误或错过任何地方。
import static java.lang.System.out;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Properties;
import java.util.List;
public class testing {
public static void main(String[] args) {
ArrayList<Elements> itemList = new ArrayList<Elements>();
try
{
System.out.println("I am in");
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("db connection");
Statement st=con.createStatement();
System.out.println("Connection estabilished"+con);
ResultSet rs=st.executeQuery("select itemname, itemcode,supplier,totalqty from table where condition");
while(rs.next()) {
Elements item=new Elements();
item.setItemname(rs.getString("Itemname"));
item.setItemcode(rs.getString("Itemcode"));
item.setSupplier(rs.getString("Supplier"));
item.setTotalqty(rs.getString("Totalqty"));
itemList.add(item);
System.out.println(itemList.size());
System.out.println(itemList.get(1).getItemname());
}
con.close();
out.println("DB Connection closed successfully");
}catch (Exception e){
System.out.println("Connection error: "+e);
}
}
}
&#13;