Guest User

Untitled

a guest
Oct 5th, 2018
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. package jdbcdemos;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.PreparedStatement;
  6. import java.sql.ResultSet;
  7. import java.sql.ResultSetMetaData;
  8. import java.sql.SQLException;
  9. import java.sql.Statement;
  10. import java.util.Scanner;
  11.  
  12. public class SelectDemo4 {
  13.  
  14.  
  15.  
  16. public static void main(String[] args) throws ClassNotFoundException, SQLException
  17. {
  18.  
  19. String address,name;
  20. int billAmount, id;
  21.  
  22. Class.forName("oracle.jdbc.driver.OracleDriver");
  23. Connection connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","tiger");
  24.  
  25. String query = "insert into customer values ( ?,?,?,?)";
  26.  
  27. Scanner scanner = new Scanner(System.in);
  28.  
  29. System.out.println("Enter the id:");
  30. id = scanner.nextInt();
  31.  
  32. System.out.println("Enter the name : ");
  33. name = scanner.nextLine();
  34.  
  35. System.out.println("Enter the address :");
  36. address = scanner.nextLine();
  37.  
  38. System.out.println("Enter the billAmount:");
  39. billAmount = scanner.nextInt();
  40.  
  41.  
  42.  
  43. PreparedStatement statement = connection.prepareStatement(query);
  44.  
  45.  
  46. statement.setInt(1,id);
  47. statement.setString(2, name);
  48. statement.setString(3, address);
  49. statement.setInt(4,billAmount);
  50.  
  51.  
  52. statement.executeUpdate();
  53. System.out.println(name+" your record saved");
  54. scanner.close();
  55. statement.close();
  56. connection.close();
  57. }
  58. }
Add Comment
Please, Sign In to add comment