Java Insert into Table JDBC Concepts

By | December 26, 2010
Java Insert into Table JDBC Concepts. You can insert the row in different database like Oracle, MySql, Access, SQL Server etc,. This Java Insert into Table DB (database) example describes the basic operations performed on the JDBC Insert into Table database connectivity code. In this example you will learn about how to write java code for Insert into Table with oracle database.

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

Leave a Reply

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