Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.*;
- public class AddEmployee{
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- System.out.println("Add Data to Table");
- Connection con = null;
- String url = "jdbc:mysql://mer.hosted.nfoservers.com:3306/";
- String dbName = "wakeandbake_junk";
- String driverName = "com.mysql.jdbc.Driver";
- String userName = "wakeandbake";
- String password = "outorrfLM9";
- try{
- Class.forName(driverName).newInstance();
- con = DriverManager.getConnection(url+dbName, userName, password);
- try{
- Statement st = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
- System.out.println("Emp Code");
- String empcode = sc.nextLine();
- System.out.println("Emp Name");
- String empname = sc.nextLine();
- String add = "INSERT INTO Employee11 (Emp_code, Emp_name) VALUES (" + empcode + ", '"+empname+"')";
- System.out.println(add);
- st.executeUpdate(add);
- System.out.println("Added");
- }
- catch(SQLException s){
- System.out.println("FAILLLLL");
- }
- con.close();
- }
- catch (Exception e){
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement