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.
  }
karikari
  • 6,627
  • 16
  • 64
  • 79
  • 1
    I think the answer is here: http://stackoverflow.com/questions/197986/what-causes-javac-to-issue-the-uses-unchecked-or-unsafe-operations-warning – Jared Farrish Jan 26 '11 at 03: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.) – Jonathan B Jan 26 '11 at 03:59

3 Answers3

1

Where did you declare the variable "driverName"?

Jonathan B
  • 1,040
  • 6
  • 11
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. :)

sarnold
  • 102,305
  • 22
  • 181
  • 238
  • Yep. I did what you suggested. Now no error for that. But new error occurs. I pasted it on my updated question. – karikari Jan 26 '11 at 03:53
0

First thing I notice is on this line:

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

Where is driverName declared?

Jared Farrish
  • 48,585
  • 17
  • 95
  • 104