Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- import java.util.Scanner;
- import java.sql.*;
- import java.util.Scanner;
- public class Driver {
- public static void main(String [] args) {
- try {
- //Get connection to DB
- Connection myConn = DriverManager.getConnection("jdbc:mysql://LocalHost:3306/interndata?useSSL=false" , "root" , "Starwars991211");
- //Create a statement
- Statement myStmt = myConn.createStatement();
- Scanner scan = new Scanner(System.in);
- int entryNum, citNum ;
- String date, score ;
- String keepGoing = "y";
- while (keepGoing.equals("y") || keepGoing.equals("Y")){
- System.out.println("Enter the id");
- entryNum = scan.nextInt();
- System.out.println("Enter the date");
- date = scan.next();
- System.out.println("Enter the citnum");
- citNum = scan.nextInt();
- System.out.println("Enter the score");
- score = scan.next();
- String sql = "INSERT INTO employee (EntryNumber, Date, ``CriterionNum, Score)" + " values (?, ?, ?, ?)";
- PreparedStatement preparedStatement = myConn.prepareStatement(sql);
- preparedStatement.setInt(1, entryNum);
- preparedStatement.setString(2, date);
- preparedStatement.setInt(3,citNum);
- preparedStatement.setString(4, score);
- preparedStatement.executeUpdate();
- System.out.print("Another factorial? (y/n) ");
- keepGoing = scan.next();
- }
- //Execute SQL query
- ResultSet myRs = myStmt.executeQuery("select * from teacherexample");
- //process result set
- while (myRs.next()) {
- System.out.println("ID: " + myRs.getInt("EntryNumber") + " Name: " + myRs.getString("Date") + ", " + myRs.getInt("CriterionNum") + " " + myRs.getString("Score"));
- }
- }
- catch (Exception exc) {
- exc.printStackTrace();
- }
- }
- com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'interndata.employee' doesn't exist
Add Comment
Please, Sign In to add comment