Update Table Code in Java using JDBC Concept

By | December 26, 2010
Update Table Code in Java JDBC Concepts. This Java Update Table Code DB (database) example describes the basic operations performed on the JDBC Update Table database connectivity code.In this example you will learn about how to write java code for Update Table with oracle database.
Are you looking for Java Code which help you to update the table values into database table. Then you are into correct place only. The following program will help to update the set of fields into database for particular rows selection. In this following program i am updating the user password by selecting the particular user.
Program:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class UpdateRow {
public static void main(String args[]){
Connection con=null;
Statement st = null;
try{
Class.forName(“oracle.jdbc.driver.OracleDriver”);
con=DriverManager.getConnection(“jdbc:oracle:thin:@localhost:1521:ORCL”,”scott”,”tiger”);
st = con.createStatement();
int b;
b=st.executeUpdate(“update eshusoft set password=’mypwd2′ where username=’myuser'”);
System.out.print(“rows updated: “+b);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Result:
rows updated: 1

Leave a Reply

Your email address will not be published. Required fields are marked *