The following Core Java database connection program will help you to understand how to insert data into Oracle database tables through java code. This simple Java example program will make you to understand the flow and steps to develop Java Insert into table concept.
Program:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class InsertRowIntoTable{
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(“insert into eshusoft values(‘myuser’,’mypwd’)”);
System.out.print(“rows inserted: “+b);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Result:
rows inserted: 1