java swing中的List如何让数据库中的信息显示代码???
privatevoidbutton1ActionPerformed(java.awt.event.ActionEventevt){//TODOaddyourhandlin...
private void button1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here:
String sql = "select *from Table_Sell";
TextArea jt=new TextArea();
ArrayList lt=new ArrayList();
/*List lt = new List(10, false);*/
lt.add("sno");
lt.add("sname");
lt.add("sprice");
lt.add("samount");
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection con = DriverManager.getConnection(
"jdbc:sqlserver://localhost:1433;"
+ "DatabaseName=ShopManager;SelectMethod=Cursor",
"sa", "");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(sql);
while (rs.next()) {
/*jt.setText(rs.getString("sno"));
jt.setText(rs.getString("sname"));
jt.setText(rs.getString("sprice"));
jt.setText(rs.getString("samount"));*/
/*Sellinfor sf = new Sellinfor();
sf.setSno(rs.getString("sno"));
sf.setSname(rs.getString("sname"));
sf.setSprice(rs.getFloat("sprice"));
sf.setSamount(rs.getString("samount"));*/
}
} catch (ClassNotFoundException e) { // TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
} 展开
String sql = "select *from Table_Sell";
TextArea jt=new TextArea();
ArrayList lt=new ArrayList();
/*List lt = new List(10, false);*/
lt.add("sno");
lt.add("sname");
lt.add("sprice");
lt.add("samount");
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection con = DriverManager.getConnection(
"jdbc:sqlserver://localhost:1433;"
+ "DatabaseName=ShopManager;SelectMethod=Cursor",
"sa", "");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(sql);
while (rs.next()) {
/*jt.setText(rs.getString("sno"));
jt.setText(rs.getString("sname"));
jt.setText(rs.getString("sprice"));
jt.setText(rs.getString("samount"));*/
/*Sellinfor sf = new Sellinfor();
sf.setSno(rs.getString("sno"));
sf.setSname(rs.getString("sname"));
sf.setSprice(rs.getFloat("sprice"));
sf.setSamount(rs.getString("samount"));*/
}
} catch (ClassNotFoundException e) { // TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询