Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package C;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.Statement;
- import java.util.Scanner;
- public class jdbc2 {
- static void getconnection()
- {
- try{
- Class.forName("oracle.jdbc.driver.OracleDriver");
- Connection conn=DriverManager.getConnection
- ("jdbc:oracle:thin:@localhost:1521:xe","system","oracle");
- Statement st=conn.createStatement();
- conn.setAutoCommit(true);
- String sql="CREATE TABLE REGISTRATION" + "(id INTEGER," + " first VARCHAR(10)," + " last VARCHAR(10),"+" age INTEGER)";
- //st.executeUpdate(sql);
- PreparedStatement ps=conn.prepareStatement("insert into registration values(?,?,?,?)");
- for(int i=0;i<3;i++)
- {
- System.out.println("enter table data id,firstname,lastname,age");
- Scanner s1=new Scanner(System.in);
- int id=s1.nextInt();
- String first=s1.next();
- String last=s1.next();
- int age=s1.nextInt();
- ps.setInt(1,id);
- ps.setString(2, first);
- ps.setString(3, last);
- ps.setInt(4,age);
- ps.executeUpdate();
- }
- ResultSet rs=st.executeQuery("select * from registration");
- while(rs.next())
- {
- System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3)+" "+rs.getInt(4));
- }
- }
- catch (Exception e) {
- System.out.println("hello");
- e.printStackTrace();
- }
- }
- public static void main(String[] args) {
- getconnection();
- }
- }
Add Comment
Please, Sign In to add comment