Friday, February 11, 2011

Insert_Records

//inserting values into a table student

import java.sql.*;
public class Insert_Records

{
public static void main(String args[])
{
try
{
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
System.out.println("thin driver is registerd");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","system");
System.out.println("Connection is established to DB");
Statement stmt=con.createStatement();
System.out.println("Statement object is created");
int a=stmt.executeUpdate("insert into student values(1,'rahul','hyd')");
System.out.println("Values are inseted -------> "+a);
}
catch(Exception e)
{
e.printStackTrace();
System.out.println("Registeration faild");
}
}
}

/*
Explanation:

Here we use a SQL insert Query
and it returns an interger value it indicates that how many record are inseted.

*/

No comments:

Post a Comment