1

I got this error while trying to compile the below code. I suspect that the code is not support MySQL. I want to use MySQL and try to modify it, but it cannot compile.

QuadrantSystemRDB.java:183: cannot find symbol
symbol  : variable driverName
location:class edu.indiana.iucbrf.examples.quadrantRDBTemplate.QuadrantSystemRD
B
        dbInfo = new DBInfo(new JDBCDriverInfo(driverName, url, username, passwo
rd),constantsTableName);
                                               ^
Note: QuadrantSystemRDB.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error

Code:

    private void setupInfo() {

    Driver driver = new com.mysql.jdbc.Driver();
    String url = "jdbc:mysql://localhost:3306/test";
    String username = "root";
    String password = "123456";

    String problemFeatureSpecTableName = "ProblemFeatureSpec";
    String solutionFeatureSpectTableName = "SolutionFeatureSpec";
    String classTableName = "Class";
    String extraDataTableName = "ExtraData";
    String casebaseTablename = "CaseBase";
    String problemTableName = "Problem";
    String solutionTableName = "Solution";
    String inactiveContextsTableName = "InactiveContext";
    String constantsTableName = "Constants";
    dbInfo = new DBInfo(new JDBCDriverInfo(driverName, url, username, password),constantsTableName);
    problemSpecInfo = new FeatureSpecRDBInfo(problemFeatureSpecTableName, classTableName, extraDataTableName);
    solutionSpecInfo = new FeatureSpecRDBInfo(solutionFeatureSpectTableName, classTableName, extraDataTableName);
    rdbCasebaseInfo = new RDBCaseBaseInfo(casebaseTablename, solutionTableName, problemTableName, inactiveContextsTableName);
}

Edit:

Here is my echoed classpath-->

C:\Documents and Settings\user>echo %classpath% .;C:\Program Files\Java\jre6\lib\ext\QTJava.zip;C:\iucbrf\;C:\mysql-connector-ja va-5.1.14-bin.jar;C:\iucbrf.jar

Edit 2:

I changed driverName to driver. Now the error is...

 QuadrantSystemRDB.java:167: unreported exception java.sql.SQLException; must be
 caught or declared to be thrown
            Driver driver = new com.mysql.jdbc.Driver();
                            ^
 Note: QuadrantSystemRDB.java uses unchecked or unsafe operations.
 Note: Recompile with -Xlint:unchecked for details.
 1 error

edit 3:

try
  {
    Driver driver = new com.mysql.jdbc.Driver();
    String url = "jdbc:mysql://localhost:3306/test";
    String username = "root";
    String password = "123456";

catch (Exception e)
  {
   // message.
  }
2
  • 1
    I think the answer is here: stackoverflow.com/questions/197986/… Commented Jan 26, 2011 at 3:42
  • 1
    This is an entirely new question. But as a pointer, you must catch any exceptions that are thrown by the class initializer (in this case, the exception is SQLException.) This is a pretty simple problem in Java, so I suggest that you read up on the basics of Java and exception handling before continuing. (Or mark this as homework.) Commented Jan 26, 2011 at 3:59

3 Answers 3

1

You initialize but never use driver.

You use driverName but never initialize it.

Is the solution as easy as changing driverName to driver? :)

EDIT:

QuadrantSystemRDB.java:167: unreported exception java.sql.SQLException; must be
caught or declared to be thrown
    Driver driver = new com.mysql.jdbc.Driver();

I think the com.mysql.jdbc.Driver() can throw an exception; you either need to wrap it in a try/catch block or declare that your method throws that same exception. Your choice which one leads to a cleaner design, but a simple try/catch can allow the compilation to succeed very quickly. :)

Sign up to request clarification or add additional context in comments.

1 Comment

Yep. I did what you suggested. Now no error for that. But new error occurs. I pasted it on my updated question.
1

Where did you declare the variable "driverName"?

5 Comments

am trying to find it. it is not inside the same file though
I found at the top of the file, it is declared as this: DBInfo dbInfo;
Is it declared as a variable somewhere in the enclosing class? Another alternative: are you implementing any interfaces in this class?
That's a declaration for the variable dbinfo. This is saying that the variable "driverName" is not declared.
I changed driverName to driver. But still have another error. I updated my question.
0

First thing I notice is on this line:

dbInfo = new DBInfo(new JDBCDriverInfo(driverName, url, username, password), constantsTableName);

Where is driverName declared?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.