我不知道如何在 TextArea 字段中正确显示 2 个表中的数据。我在数据库表中添加了 2 行,但程序在 textArea 中显示 4 行而不是 2(重复),如果我添加 3 行程序显示 3x 第一行、3x 第二行、3x 第三行……等等。这是我的代码. 请以某种方式帮助我:(
jTextArea1.setText(null);
Connection connection=null;
try
{
String driverName="oracle.jdbc.driver.OracleDriver";
Class.forName(driverName);
String serverName = "193.2.139.xxx";
String portNumber = "1521";
String sid = "ers";
String url = "jdbc:oracle:thin:@"+serverName+":"+portNumber+":"+sid;
String username = "xxxxxxxx";
String password = "xxxxxxxxxx";
connection = DriverManager.getConnection(url, username, password);
java.sql.Statement select = connection.createStatement();
int id;
String name; //column from table narocnik
String surname; //column from table narocnik
String address; //column from table narocnik
String telephone; //column from table narocnik
String date; //column from table prevoz
String od; //column from table prevoz
String v; //column from table prevoz
String odhod; //column from table prevoz
String cena; //column from table prevoz
ResultSet rs1=select.executeQuery("select * from narocnik,prevoz");
while(rs1.next()){
id=rs1.getInt("id");
name=rs1.getString("name");
surname=rs1.getString("surname");
address=rs1.getString("address");
telephone=rs1.getString("telephone");
date=rs1.getString("date");
od=rs1.getString("od");
v=rs1.getString("do");
odhod=rs1.getString("odhod");
cena=rs1.getString("cena");
jTextArea1.append(name+", "+surname+", "+address+", "+telephone+", "+date+", "+od+", "+v+", "+odhod+", "+cena+"\n");
}
connection.close();
}
catch(ClassNotFoundException e)
{
JOptionPane.showMessageDialog(this,"Ni gonilnika! "+e);
}catch(SQLException e){
JOptionPane.showMessageDialog(this,"Napaka pri povezavi! "+e);
}