Symbianize Forum

Most of our features and services are available only to members, so we encourage you to login or register a new account. Registration is free, fast and simple. You only need to provide a valid email. Being a member you'll gain access to all member forums and features, post a message to ask question or provide answer, and share or find resources related to mobile phones, tablets, computers, game consoles, and multimedia.

All that and more, so what are you waiting for, click the register button and join us now! Ito ang website na ginawa ng pinoy para sa pinoy!

Java using Netbeans Add Edit Delete problems.

duncedusk21

Apprentice
Advanced Member
Messages
97
Reaction score
1
Points
28
hello ts, newbie lang po sa java. pa help naman po. nag try ako mag update record sa textfields. kaya lang kelangan ko pa i close ung program then run the program uli para makita yung updated data sa textfields.

is there a way po ba para ma refresh yung data para hindi ako lagi mag close application?

maraming salamat po. :)

Code:
 // Update Record Button
String colCountry = txtCountry.getText();
String colCapital = txtCapital.getText(); 
String colCurrency = txtCurrency.getText(); 
String colContinent = txtContinent.getText();
String colID = txtCID.getText(); 
            
int newColID = Integer.parseInt(colID);
            
String sql = "UPDATE TBLCOUNTRY set COUNTRYID ='"+newColID+"',COUNTRY='"+colCountry+"',CAPITAL='"+colCapital+"',CURRENCY='" +colCurrency+"',CONTINENT='" +colContinent+"' where COUNTRYID='"+newColID+"'";
            
JOptionPane.showMessageDialog(MRDBCountry.this, "Record Updated!");
            
pst=dbCon.prepareStatement(sql);
pst.execute();
 
parang wala naman need iupdate sa UI, kasi kung saan ka kumuha ng data, yun din yung pang update mo?

TIPS:
use PreparedStatement na ang structure ay
Code:
int countryId = ...;
sql = "UPDATE country(continent, capital)  VALUES(?,?) WHERE id = ?";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, "ASIA"); // maps 1 to first ?
ps.setString(2, "MANILA"); // maps 2 to second ?
ps.setInteger(3, countryId); // maps 3 to last ?

// if there are projected updates in the table, always use executeUpdate()
// if (ps.executeUpdate() > 0) checks if there are updated records
if(ps.executeUpdate() > 0) { 
// do something if something was updated
}

yung tamang paggamit ng PreparedStatement, mas madali, reusable, saka anti-SQL injection
 
thanks sir. yung scenario po is nakaload na po ung record sa textfields, may first, next, previous and last buttton sa UI. Let say sa last record nag update po ako ng data. Yung update record button gumana po yung code. yun lang after ma click ung update button need ko pa iclose yung program and run the program pra mag take effect ung updated na record sa textfields.

thank you po uli.
 
okay okay, hindi problema yung pagupdate, ang problem is sinasave mo sa collection yung records galing sa db pagbukas ng application,
so hindi mo nababago yung record dun sa collection kahit na inupdate mo na sya sa db

solutions:
a. refresh laman ng collection
b. iupdate mo yung mismong data sa collection if naupdate nga sya sa db
c. wag ka gumamit ng collection, magpointer ka kung anong index na sya sa db, medyo mahirap to, pero eto pinakapreferred ko
 
sir pano po yung refresh sa laman ng collection? thank you sir.
 
nagawa mo na yon ng di mo napapansin, kasi tingin ko yun yung ginawa mo kaya di naguupdate yung sa UI
 
hello ts, newbie lang po sa java. pa help naman po. nag try ako mag update record sa textfields. kaya lang kelangan ko pa i close ung program then run the program uli para makita yung updated data sa textfields.

is there a way po ba para ma refresh yung data para hindi ako lagi mag close application?

maraming salamat po. :)

Code:
 // Update Record Button
String colCountry = txtCountry.getText();
String colCapital = txtCapital.getText(); 
String colCurrency = txtCurrency.getText(); 
String colContinent = txtContinent.getText();
String colID = txtCID.getText(); 
            
int newColID = Integer.parseInt(colID);
            
String sql = "UPDATE TBLCOUNTRY set COUNTRYID ='"+newColID+"',COUNTRY='"+colCountry+"',CAPITAL='"+colCapital+"',CURRENCY='" +colCurrency+"',CONTINENT='" +colContinent+"' where COUNTRYID='"+newColID+"'";
            
JOptionPane.showMessageDialog(MRDBCountry.this, "Record Updated!");
            
pst=dbCon.prepareStatement(sql);

pst.execute(); 
JOptionPane.showMessageDialog(MRDBCountry.this, "Record Updated!");

setTextnewColID(newColID);


gawa ka ng method setText();

Code:
setText(int newColID) {
// i call mo dito yung ginamit mong pang pull ng record sa db 
// sample lang, parang ganto. Pero sana nasa method lang para isang call updated lahat
newValCurrency = SELECT CURRENCY FROM TBLCOUNTRY WHERE COUNTRYID =  newColID;
jTextField.setText(newValCurrency);

Ang logic is
You update the database therefore you have to make a new select query for the new value and set those newly pulled data to the text fields... :D :D


}
 
Last edited:
nagawa mo na yon ng di mo napapansin, kasi tingin ko yun yung ginawa mo kaya di naguupdate yung sa UI

salamat sir. God bless :)

- - - Updated - - -

gawa ka ng method setText();

Code:
setText(int newColID) {
// i call mo dito yung ginamit mong pang pull ng record sa db 
// sample lang, parang ganto. Pero sana nasa method lang para isang call updated lahat
newValCurrency = SELECT CURRENCY FROM TBLCOUNTRY WHERE COUNTRYID =  newColID;
jTextField.setText(newValCurrency);

Ang logic is
You update the database therefore you have to make a new select query for the new value and set those newly pulled data to the text fields... :D :D


}

maraming salamat po. God bless :)
 
Back
Top Bottom