Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package javaapplication;
- import java.sql.*;
- import java.util.Scanner;
- /**
- *
- * @author Student
- */
- public class JavaApplication {
- public static final String USERNAME="root";
- public static final String PASSWORD="";
- public static final String CONN_STRING="jdbc:mysql://localhost:3306/db2";
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- String Fname, Lname, City;
- int EID, Zip, Salary, Age;
- Scanner s = new Scanner(System.in);
- System.out.print("Enter First Name: ");
- Fname = s.nextLine();
- System.out.print("Enter Last Name: ");
- Lname = s.nextLine();
- System.out.print("Enter City: ");
- City = s.nextLine();
- System.out.print("Enter Zip Code: ");
- Zip = s.nextInt();
- System.out.print("Enter Age: ");
- Age = s.nextInt();
- System.out.print("Enter Salary: ");
- Salary = s.nextInt();
- Connection conn=null;
- try{
- conn=DriverManager.getConnection(CONN_STRING, USERNAME, PASSWORD);
- System.out.println("Connected");
- Statement stmt=(Statement)conn.createStatement();
- String insert="INSERT INTO `db2`.`db1employees` (`EmployeeID`, `FirstName`, `LastName`, `City`, `Zipcode`, `Age`, `Salary`) VALUES (NULL, '"+Fname+"', '"+Lname+"', '"+City+"', '"+Zip+"', '"+Age+"', '"+Salary+"');";
- stmt.executeUpdate(insert);
- }
- catch(SQLException e){
- System.err.println(e);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement