java - "Cannot find symbol" problem when using Class.forName() -
I can not find the symbol
from my code Does anyone know that this problem What could be the reason?
The code is:
// Register JDBC driver Class.forName ("net.sourceforge.jtds.jdbc.Driver");
and error output is:
blah.java314: symbol symbol can not be found: method forName (java.lang.String) Location: Class Java.lang.Class class. ForName ("net.sourceforge.jtds.jdbc.Driver"); ^ 1 Error
// STEP 1. Import the necessary package java.sql Import. *; Public class JDBCExample {// JDBC driver name and database URL fixed final string JDBC_DRIVER = "com.sql.jdbc.Driver"; Fixed final string DB_URL = (": jdbc: jtds: sqlserver: // localhost: 1433 / tempdb"); // database credentials static last string USER = "username"; Fixed final string PASS = "password"; Public static zero main (string [] args) {connection conn = null; Description stmt = null; Try {// STEP 2: Register JDBC Driver Class. ForName ("net.sourceforge.jtds.jdbc.Driver"); // STEP 3: Open a connection System.out.println ("Connecting to the database ..."); Conn = DriverManager.getConnection (DB_URL, USER, PASS); // STEP 4: Perform a Query System.out.println ("Creating a Database ..."); Stmt = conn.createStatement (); String sql = "create database"; Stmt.executeUpdate (SQL); System.out.println ("The database was created successfully ..."); } Hold (from eclipsection) {// handle errors for JDBC se.printStackTrace (); } Hold (Exception E) {// Handle Errors for Class e.printStackTrace (); } Finally {// Finally try the block used to close resources {if (stmt! = Null) stmt.close (); } Hold (SQLException se2) {} // nothing can we try {if (conn! = Null) conn.close (); } Hold (from eclipsection) {se.printStackTrace (); } // Finally try} / / end attempt system.out.println ("bye"); } // end main} // end JDBCExample
The main method in which class .forName ()
may fail that Zbb driver is not available on the class path, but it will be a run-time error, there is not a compile-time error as you start getting here.
Using my powers of mental debugging, I think that you can use GWT. I do not believe it allows the client side (where it has been converted to javascript) All JDBC accessories have to be on the server side. GetAnumConstants ()
If I About the fact that you are using, GWT is probably best to use GWT-RPC to talk between client and server, and the server automatically releases JDBC calls.
If you need more information on GWT-RPC, see. GWT is one of the news groups in which you can read for more information.
Comments
Post a Comment