开发者

Error while trying to use Mysql for my Java program

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";
    Strin开发者_StackOverflowg 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.
  }


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. :)


Where did you declare the variable "driverName"?


First thing I notice is on this line:

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

Where is driverName declared?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜