javanetbeansconnectioncannot-find-symbol

Cannot find Connection, DriverManager and Statement variables in netbeans using ucanaccess


I am not a programmer and basically this is like a cut-and-paste assignment from our lecturer which did not turn out well for me. Here is the code:

try
       {
         Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
         String path = "C:\\MyDatabaseSDDNOV2022\\MyDatabaseSDDNOV2022.mdb";
         String url = "jdbc:ucanaccess://" + path;
         Connection c= DriverManager.getConnection(url);
          Statement stinsert=c.createStatement();
          String Sql = "Insert into Students(StudentName,StudentAge,EnrollmentDate,EnrolledCLasses,StudentAddress,StudentContactNumber,TeacherComment) Values (";
          Sql = Sql +"'" + txtSName.getText() +"','";
          Sql = Sql + txtSAge.getText() + "','";
          Sql = Sql + txtEDate.getText() + "','";
          Sql = Sql + txtEClass.getText() + "','";
          Sql = Sql + txtSAddress.getText() + "','";
          Sql = Sql + txtSContact.getText() + "','";
          Sql = Sql + txtTComment.getText() + "')";
              lblSql.setText(Sql);
              stinsert.executeUpdate(Sql);
              lblSql.setText("Record Inserted");
       
       
    }                                         
       catch (Exception E) {

This is code to get data from a filled-out form into a microsoft access database for the add button. The whole code seems fine except that netbeans continues to give off an error that 'symbol could not be found' and the symbols in question are the Connection, DriverManager and Statement. I've downloaded all the jar files into the library and after telling my lecturer the issue, he told me to google it. Is there a problem with netbeans (latest) or the ucanaccess jar files? Thank you for your time! I don't understand a lot of jargon and the course is a management course.

Said enough. Thank you. Is this code reusable for the edit and delete function as well? Thank you again


Solution

  • Without to know something about programming, you should see the begening of this .java file, and check these lines in (if not, insert these lines) after package .... line:

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

    In these cases in NetBeans try to use the menu Source -> Fix Imports ... and Organize Imports.