Guest User

Untitled

a guest
Feb 8th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. import java.sql.*;
  2. import java.util.Scanner;
  3.  
  4. import java.sql.*;
  5. import java.util.Scanner;
  6.  
  7. public class Driver {
  8. public static void main(String [] args) {
  9. try {
  10. //Get connection to DB
  11. Connection myConn = DriverManager.getConnection("jdbc:mysql://LocalHost:3306/interndata?useSSL=false" , "root" , "Starwars991211");
  12. //Create a statement
  13. Statement myStmt = myConn.createStatement();
  14.  
  15. Scanner scan = new Scanner(System.in);
  16.  
  17. int entryNum, citNum ;
  18. String date, score ;
  19. String keepGoing = "y";
  20.  
  21. while (keepGoing.equals("y") || keepGoing.equals("Y")){
  22. System.out.println("Enter the id");
  23. entryNum = scan.nextInt();
  24. System.out.println("Enter the date");
  25. date = scan.next();
  26. System.out.println("Enter the citnum");
  27. citNum = scan.nextInt();
  28. System.out.println("Enter the score");
  29. score = scan.next();
  30. String sql = "INSERT INTO employee (EntryNumber, Date, ``CriterionNum, Score)" + " values (?, ?, ?, ?)";
  31. PreparedStatement preparedStatement = myConn.prepareStatement(sql);
  32. preparedStatement.setInt(1, entryNum);
  33. preparedStatement.setString(2, date);
  34. preparedStatement.setInt(3,citNum);
  35. preparedStatement.setString(4, score);
  36. preparedStatement.executeUpdate();
  37. System.out.print("Another factorial? (y/n) ");
  38. keepGoing = scan.next();
  39. }
  40. //Execute SQL query
  41. ResultSet myRs = myStmt.executeQuery("select * from teacherexample");
  42. //process result set
  43. while (myRs.next()) {
  44. System.out.println("ID: " + myRs.getInt("EntryNumber") + " Name: " + myRs.getString("Date") + ", " + myRs.getInt("CriterionNum") + " " + myRs.getString("Score"));
  45. }
  46. }
  47. catch (Exception exc) {
  48. exc.printStackTrace();
  49. }
  50. }
  51.  
  52. com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'interndata.employee' doesn't exist
Add Comment
Please, Sign In to add comment