0

我想知道如何在插入新行而不重新打开整个应用程序后刷新数据库。我希望能够在我的应用程序的后续步骤中看到新数据。我找不到任何解决方案,所以如果您发布示例,我会很高兴。当然如果可能的话。这是我的连接方法

    try{
    String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
    Class.forName(driver);

    String db = "jdbc:odbc:FlowValves";
    con = DriverManager.getConnection(db);
    st = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);

    }catch(Exception ex){
        ex.printStackTrace();
    }

这是我的一种插入方法。

    String sql = "select * from Typy";
    try{
        ResultSet result;
        result = st.executeQuery(sql);
        result.moveToInsertRow();

        String stringNazwa = (String)nazwaZaworuField.getText();
        result.updateString("Typ", stringNazwa);

        String stringDN = (String)dnZaworuField.getText();
        result.updateString("DN", stringDN);

        String stringPN = (String)pnZaworuField.getText();
        result.updateString("PN", stringPN);

        String stringIndeks = (String)indeksField.getText();
        result.updateString("Indeks", stringIndeks);

        result.insertRow();
        result.close();

        JOptionPane.showMessageDialog(null, "Wprowadzono dane", "Komunikat", JOptionPane.INFORMATION_MESSAGE);
    }catch(Exception ex){
        ex.printStackTrace();
    }        
4

1 回答 1

0

您的插入代码看起来是正确的(尽管我会使用 insert 语句而不是 using moveToInsertRow()

您应该能够重新查询数据库并将新数据放在屏幕上:

String sql = "select * from Typy";
ResultSet result;
result = st.executeQuery(sql);

while( result.next() ){

   sting indeks = result.getString( "indeks" );
   // etc.

   // do something with the new data

}
于 2013-06-20T18:22:30.687 回答