import java.sql.*;
class ExOnSequencePKGeneration
{
public static void main(String[] args) throws Exception
{
int i=0;
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","advjava","advjava");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select docidseq.nextval from dual");
if(rs.next())
i=rs.getInt(1);//102
PreparedStatement pstmt=con.prepareStatement("insert into doctor values(?,?,?)");
pstmt.setInt(1,i);
pstmt.setString(2,args[0]);
pstmt.setString(3,args[1]);
pstmt.executeUpdate();
System.out.println("Record Inserted with Sequence Value");
rs.close();
pstmt.close();
st.close();
con.close();
}
}
No comments:
Post a Comment