ADVANCED JAVA PROGRAMMING
Steps for writing a JDBC program
Smt. M.Jeevana Sujitha
Assistant Professor
Department of Computer Science and Engineering
SRKR Engineering College, Bhimavaram, A.P. - 534204
OBJECTIVES
The Objective of this lecture is
Steps for Writing a JDBC Program
Step-1: Register the driver or loading the driver
Syntax:
Class.forName(“url”); DriverManager.registerDriver(“url”); System.setProperty(“url”);
Step-2: Establishing the connection to a database
Syntax:
Connection con=DriverManager.getConnection(“url”);
Steps for Writing a JDBC Program
Step-3: Preparing SQL statement
Syntax:
Statement st=con.createStatement();
PreparedStatement ps=con.prepareStatement(“sql query”);
Step-4: Executing the SQL statement
Syntax:
Boolean b=st.execute(“sql query”);
int i=st.executeUpdate(“insert or delete or update query”);
ResultSet rs=st.executeQuery(“select query”);
Steps for Writing a JDBC Program
Step-5: Retrieving the Results
stored in an object with the help of ResultSet interface.
Syntax:
ResultSet rs=st.executeQuery(“select * from table name”);
pointed before the first row of table.
method.
Step-6: Close the Connection
Syntax:
con.close();
THANK YOU