Question

I am working on this code and keep getting errors like "ERROR: Syntax error: Encountered "<EOF>"...

I am working on this code and keep getting errors like

"ERROR: Syntax error: Encountered "<EOF>" at line 1, column 169."

and

"ERROR: Table/View 'STUDENT' does not exist.
ERROR: Table/View 'STUDENT' does not exist.
ERROR: Table/View 'STUDENT' does not exist."

I do not know why this isn't working. Here is my code:

DTCCDatabase.java


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/**
* This program creates the CoffeeDB database.
*/
public class DTCCDatabase {
   public static void main(String[] args)
   {
       // Create a named constant for the URL.
       // NOTE: This value is specific for Java DB.
       final String DTCC_URL = "jdbc:derby:DTCCDatabase;create=true";

       try
       {
           // Create a connection to the database.
           Connection conn = DriverManager.getConnection(DTCC_URL);

           // If the DB already exists, drop the tables.
           dropTables(conn);

           // Build the Coffee table and insert records.
           buildStudentTable(conn);

           // Close the connection.
           conn.close();
          
           System.out.println("DB creation success!");
       }
       catch (Exception ex)
       {
           System.out.println("ERROR: " + ex.getMessage());
       }
   } // end main
  
   /**
   * The buildCoffeeTable method creates the
   * Coffee table and adds some rows to it.
   */
   public static void buildStudentTable(Connection conn)
   {
       try
       {
           // Get a Statement object.
           Statement stmt = conn.createStatement();

           // Create the table.
           stmt.execute( "CREATE TABLE STUDENTS (Student_ID CHAR(25) NOT NULL PRIMARY KEY, "
                       + "LastName CHAR(20) NOT NULL,"
                       + "FirstName CHAR(15) NOT NULL,"
                       + "PlanOfStudy CHAR(25) NOT NULL,"
                       + "GPA Double NOT NULL" );

           // Insert row #1.
           stmt.execute( "INSERT INTO STUDENT VALUES (899090111, 'Rothlisberger', 'Ben', 'CIT', 3.7)"   );

           // Insert row #2.
           stmt.execute( "INSERT INTO STUDENT VALUES (129020202, 'Manning', 'Peyton', 'Computer Programming', 3.8)"   );

           // Insert row #3.
           stmt.execute( "INSERT INTO STUDENT VALUES (890101030, 'Brady', 'Tom', 'Accounting', 3.4 )"    );
          
           stmt.execute( "INSERT INTO STUDENT VALUES (980191919, 'Rodgers', 'Aaron', 'Networking', 3.2 )"    );
          
           stmt.execute( "INSERT INTO STUDENT VALUES (807223230, 'Manning', 'Eli', 'Securities', 3.7 )"    );


           System.out.println("Student table created.");
       }
       catch (SQLException ex)
       {
           System.out.println("ERROR: " + ex.getMessage());
       }
   } // end build
  
  
   /**
   * The dropTables method drops any existing
   * in case the database already exists.
   */
   public static void dropTables(Connection conn)
   {
       System.out.println("Checking for existing table.");

       try
       {
           // Get a Statement object.
           Statement stmt = conn.createStatement();;

           try
           {
               // Drop the Coffee table.
               stmt.execute("DROP TABLE Coffee");
               System.out.println("Coffee table dropped.");
           }
           catch(SQLException ex)
           {
               // No need to report an error.
               // The table simply did not exist.
           }
       }
       catch(SQLException ex)
       {
           System.out.println("ERROR: " + ex.getMessage());
           ex.printStackTrace();
       }
   } // end drop tables
  
} // end class

DTCCViewer.java

// Needed for JDBC classes
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;

public class DTCCViewer {

   public static void main(String[] args) {
       // Create a named constant for the URL.
       // NOTE: This value is specific for Java DB.
       final String DTCC_URL = "jdbc:derby:DTCCDatabase;create=true";

       try
       {
           // Create a connection to the database.
           Connection conn = DriverManager.getConnection(DTCC_URL);

           // view data
           viewStudentTable(conn);
          
           // modify record
           modStudentTable(conn);
          
           viewStudentTable(conn);
          
           // Close the connection.
           conn.close();

       }
       catch (Exception ex)
       {
           System.out.println("ERROR: " + ex.getMessage());
       }


   } // end main

   public static void viewStudentTable(Connection conn)
   {
       //create var for result set
       ResultSet resultset = null;

       try
       {
           // Get a Statement object.
           Statement stmt = conn.createStatement();

           // View the table.
           resultset = stmt.executeQuery("SELECT * FROM Student");

           // process results
           ResultSetMetaData metaData = resultset.getMetaData();
          
           System.out.println("Data from Student Table:");

           int numberOfColumns = metaData.getColumnCount();
           // for loop to field names
           for (int i = 1; i <= numberOfColumns; i++){
               System.out.printf("%s\t", metaData.getColumnName(i));
           }
           System.out.println();
          
           // while loop to display data
           while (resultset.next()){
               for (int i = 1; i <= numberOfColumns; i++){
                   System.out.printf("%s\t", resultset.getObject(i));
               }
               System.out.println();
           }

       }
       catch (SQLException ex)
       {
           System.out.println("ERROR: " + ex.getMessage());
       }
   }  


   public static void modStudentTable(Connection conn)
   {
       //create var for result set
       ResultSet resultset = null;

       try
       {
           // Get a Statement object.
           Statement stmt = conn.createStatement();

           // update record
           stmt.executeUpdate("UPDATE Student SET PlanOfStudy = 'WebTechnologies' WHERE FirstName = 'Tom'");
           System.out.println("Record updated");

       }
       catch (SQLException ex)
       {
           System.out.println("ERROR: " + ex.getMessage());
       }
   }  

} // end class


Please help!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Actually, you forgot to close a bracket at the end of the table creation time

look here is your code.

48 // Create the table. stmt.execute CREATE TABLE STUDENTS (student_ID CHAR(25) NOT NULL PRIMARY KEY, 49 50 51 52 53 54 Las

Now my changed code

48 49 50 51 52 53 54 // Create the table. stmt.execute( CREATE TABLE STUDENTS (student_ID CHAR(25) NOT NULL PRIMARY KEY, +L

changing this bit carefully should work.

The reason is that you have opened a bracket after CREATE TABLE STUDENTS but you have not closed it. that is why your code of DB is not running, (and the table is not created)

but code after this is syntactically correct if you run them they will try searching for the Table name STUDENTS but the code is not able to find it that is why it is returning the error.

Any problem ask me in the comment section

Thumbs up is appreciated.

Add a comment
Know the answer?
Add Answer to:
I am working on this code and keep getting errors like "ERROR: Syntax error: Encountered "<EOF>"...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I got an issue where line 48 "The method setDeveloper(String) is undefined for the type dev_selects"...

    I got an issue where line 48 "The method setDeveloper(String) is undefined for the type dev_selects" Any help is appreciated import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import java.util.Date; import gUI.newer_gui; public class dev_selects {    public static void main(String[] args) {        // TODO Auto-generated method stub        Connection conn = null;        Statement stmt = null;        String str1 = "select Developers from New_Products";        String...

  • Customer (CustomerId, CustomerName) Employee (EmployeeId, EmployeeName, Salary, SupervisorId) Product(ProductId, ProductName, ListPrice) Orders (OrderId, OrderDate, CustomerId, EmployeeId,...

    Customer (CustomerId, CustomerName) Employee (EmployeeId, EmployeeName, Salary, SupervisorId) Product(ProductId, ProductName, ListPrice) Orders (OrderId, OrderDate, CustomerId, EmployeeId, Total) OrderedProduct (OrderId, ProductId, Quantity, Price) Write the code to complete the methods in OrderJDBC.java (look for TODO items). <---**IN BOLD** throughout code. /* OrderJDBC.java - A JDBC program for accessing and updating an order database on MySQL. */ import java.io.File; import java.math.BigDecimal; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Statement; import java.util.Scanner; /** * An application for...

  • JAVA sql Code an sql file that creates a 'Contractors' table. See the exercise below for...

    JAVA sql Code an sql file that creates a 'Contractors' table. See the exercise below for an example. Give your 'Contractors' table the following fields Id (integer, primary key) CompanyName (varchar, 30 characters) Phone(varchar, 12 characters) ContactName(varchar, 30 characters) Rating (integer) OutOfStateService (boolean) Also have the sql file create at least five records for the "Contractors" table. Example record: 1, Tom's Contracting, 555-555-5555, Tom Thumb, 81, true import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class TestDB...

  • There is a problem in the update code. I need to be able to update one...

    There is a problem in the update code. I need to be able to update one attribute of the students without updating the other attributes (keeping them empty). package dbaccessinjava; import java.sql.DriverManager; import java.sql.Connection; import java.sql.SQLException; import java.sql.*; import java.io.*; import java.util.Scanner; public class DBAccessInJava { public static void main(String[] argv) {    System.out.println("-------- Oracle JDBC Connection Testing ------"); Connection connection = null; try{ Class.forName("oracle.jdbc.driver.OracleDriver"); Connection con= DriverManager.getConnection("jdbc:oracle:thin:@MF057PC16:1521:ORCL", "u201303908","pmu"); String sql="select * from student"; Statement st; PreparedStatement ps; ResultSet rs;...

  • I am currently doing homework for my java class and i am getting an error in...

    I am currently doing homework for my java class and i am getting an error in my code. import java.util.Scanner; import java.util.Random; public class contact {       public static void main(String[] args) {        Random Rand = new Random();        Scanner sc = new Scanner(System.in);        System.out.println("welcome to the contact application");        System.out.println();               int die1;        int die2;        int Total;               String choice = "y";...

  • Need Help ASAP!! Below is my code and i am getting error in (public interface stack)...

    Need Help ASAP!! Below is my code and i am getting error in (public interface stack) and in StackImplementation class. Please help me fix it. Please provide a solution so i can fix the error. thank you.... package mazeGame; import java.io.*; import java.util.*; public class mazeGame {    static String[][]maze;    public static void main(String[] args)    {    maze=new String[30][30];    maze=fillArray("mazefile.txt");    }    public static String[][]fillArray(String file)    {    maze = new String[30][30];       try{...

  • I need help debugging this Java program. I am getting this error message: Exception in thread...

    I need help debugging this Java program. I am getting this error message: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2 at population.Population.main(Population.java:85) I am not able to run this program. ------------------------------------------------------------------- import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Scanner; /* Linked list node*/ class node { long data; long year; String country; node next; node(String c,long y,long d) { country=c; year=y; data = d; next = null; } } public class Population { private static node head; public static void push(String...

  • Written in Java I have an error in the accountFormCheck block can i get help to...

    Written in Java I have an error in the accountFormCheck block can i get help to fix it please. Java code is below. I keep getting an exception error when debugging it as well Collector.java package userCreation; import java.io.IOException; import java.net.URL; import java.util.ResourceBundle; import java.util.regex.Matcher; import java.util.regex.Pattern; import javafx.event.ActionEvent; import javafx.fxml.*; import javafx.scene.*; import javafx.scene.control.*; import javafx.scene.text.Text; import javafx.stage.*; public class Controller implements Initializable{ @FXML private PasswordField Password_text; @FXML private PasswordField Confirm_text; @FXML private TextField FirstName_text; @FXML private TextField LastName_text;...

  • I am getting an error from eclipse stating that: Exception in thread "main" java.lang.Error: Unresolved compilation...

    I am getting an error from eclipse stating that: Exception in thread "main" java.lang.Error: Unresolved compilation problem: at EvenOdd.main(EvenOdd.java:10) I am unable to find what I can do to fix this issue. Can you please assist? My code is below: import java.util.InputMismatchException; import java.util.Scanner; public class EvenOdd {    public static void main(String[] args) {        Scanner input = new Scanner(System.in);        System.out.println("Welcome to this Odd program!");        int userInput1 = input.nextInt();    }       public...

  • I keep getting this error "You have an error in your SQL syntax; check the manual...

    I keep getting this error "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 4" line 4 is the "Genre char(20) not null," any help or guidance would be lovely create table Games      (gameid int not null auto_increment primary key,       title varchar(100) not null,       Genre char(20) not null,       year_released int not null);      insert into Games(title, Genre,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT