Advertisement
Guest User

Untitled

a guest
Jun 30th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.37 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.ResultSet;
  4. import java.sql.SQLException;
  5. import java.sql.Statement;
  6. import java.util.*;
  7.  
  8. public class AddEmployee{
  9.   public static void main(String[] args) {
  10.      
  11.     Scanner sc = new Scanner(System.in);
  12.     System.out.println("Add Data to Table");
  13.     Connection con = null;
  14.     String url = "jdbc:mysql://mer.hosted.nfoservers.com:3306/";
  15.     String dbName = "wakeandbake_junk";
  16.     String driverName = "com.mysql.jdbc.Driver";
  17.     String userName = "wakeandbake";
  18.     String password = "outorrfLM9";
  19.     try{
  20.       Class.forName(driverName).newInstance();
  21.       con = DriverManager.getConnection(url+dbName, userName, password);
  22.       try{
  23.         Statement st = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
  24.         System.out.println("Emp Code");
  25.         String empcode = sc.nextLine();
  26.         System.out.println("Emp Name");
  27.         String empname = sc.nextLine();
  28.         String add = "INSERT INTO Employee11 (Emp_code, Emp_name) VALUES (" + empcode + ", '"+empname+"')";
  29.         System.out.println(add);
  30.         st.executeUpdate(add);
  31.         System.out.println("Added");
  32.       }
  33.       catch(SQLException s){
  34.         System.out.println("FAILLLLL");
  35.       }
  36.       con.close();
  37.     }
  38.     catch (Exception e){
  39.       e.printStackTrace();
  40.     }
  41.   }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement