Guest User

Untitled

a guest
Mar 20th, 2018
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.83 KB | None | 0 0
  1. import java.sql.*;
  2. import java.util.*;
  3.  
  4. class InputSeeker{
  5.     Scanner sc = new Scanner(System.in);
  6.     // Name seeker
  7.     public String nameSeeker(){
  8.         System.out.println("Enter the Name you want to add: ");
  9.         String name = sc.next();
  10.         return name;
  11.     }
  12.     // id seeker
  13.     public int idSeeker() {
  14.         System.out.println("Assign the Participant an id : ");
  15.         int id= sc.nextInt();
  16.         return id;
  17.     }
  18.     //number seeker
  19.     public float amountSpentSeeker() {
  20.         System.out.println("Enter the amount: ");
  21.         float amountSpent= sc.nextFloat();
  22.         return amountSpent;
  23.     }
  24.     //mobile number
  25.     public String mobileNumberSeeker() {
  26.         System.out.println("Enter the mobile number: ");
  27.         String mobileNumber=sc.next();
  28.         return mobileNumber;
  29.     }
  30.     //group id  
  31.     public int groupIdSeeker() {
  32.         System.out.println("Assign the Group an id: ");
  33.         int groupid= sc.nextInt();
  34.         return groupid;
  35.     }
  36. }
  37.  
  38. class UserL{
  39.     int userId;
  40.     String userName;
  41.     float amountSpent;
  42.     String mobileNumber;
  43.     int groupId;
  44. }
  45.  
  46. class UserDAO{
  47.     Connection con =null;
  48.     public void connect(){
  49.         try {
  50.             Class.forName("com.mysql.jdbc.Driver");
  51.             con= DriverManager.getConnection("jdbc:mysql://localhost:3306/markone","root","nishant97");
  52.         } catch (Exception ex) {
  53.             System.out.println(ex);
  54.         }
  55.             }
  56.    
  57.     public void addUser_catalogue(UserL u) {
  58.        
  59.        
  60.         String query ="insert into user_catalogue value(?,?,?,?)";
  61.        
  62.         try {
  63.            
  64.             PreparedStatement pst = con.prepareStatement(query);
  65.             pst.setInt(1,u.userId);
  66.             pst.setString(2,u.userName);
  67.             pst.setInt(3,u.groupId);
  68.             pst.executeUpdate();
  69.            
  70.         } catch (Exception ex) {
  71.             System.out.println(ex);
  72.         }
  73.     }
  74.    
  75. }
  76. public class User{
  77.     public static void main(String[] args){
  78.         UserDAO dao = new UserDAO();
  79.         dao.connect();
  80.         UserL ul2= new UserL();
  81.         InputSeeker is1 = new InputSeeker();
  82.         ul2.userId=is1.id;
  83.        
  84.     }
  85. }
Add Comment
Please, Sign In to add comment