Friday, November 4, 2011

Common Error Messages JDK, MySQL, Tomcat, JDBC, Servlet ...


Common Error Messages

JDK, MySQL, Tomcat, JDBC, Servlet ...

Murphy's law states that:
  • "Anything that can possibly go wrong, does."
  • "Everything that can possibly go wrong will go wrong."
  • "If anything can go wrong, it will."
  • "If there is any way to do it wrong, he will."
When software goes wrong, the MOST IMPORTANT thing to do is to FIND the ERROR MESSAGE, which can give you a clue of what went wrong. If things were running fine until the lightning strikes, ask yourself what have you CHANGED!
Search this document with you Error Message; or simple google your error message.
Stack Trace
Most of the times, the error message consists of tens of lines of so-called stack trace of method invocation. That is, method A called method B, which called method C, and so on, until method Z encountered an error and threw an Exception or an Error. It is important to:
  1. Get to the first line of the error message to read the description, and
  2. Look for the line number of YOUR program that triggered the error.
For example, this error message (stack trace) has 40 over lines:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure  <== First line with error description
The last packet sent successfully to the server was 0 milliseconds ago.
The driver has not received any packets from the server.
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
        at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
        at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1116)
        at com.mysql.jdbc.MysqlIO.(MysqlIO.java:344)
        at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2333)
        at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2370)
        at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2154)
        at com.mysql.jdbc.ConnectionImpl.(ConnectionImpl.java:792)
        at com.mysql.jdbc.JDBC4Connection.(JDBC4Connection.java:47)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
        at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
        at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:381)
        at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
        at java.sql.DriverManager.getConnection(DriverManager.java:579)
        at java.sql.DriverManager.getConnection(DriverManager.java:221)
        at MySQLJdbcTestJDK7.main(MySQLJdbcTestJDK7.java:7)         <== Your program's line number here (line 7)
Caused by: java.net.ConnectException: Connection refused: connect   <== First line of another related error
        at java.net.DualStackPlainSocketImpl.connect0(Native Method)
        at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:69)
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:337)
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:198)
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:180)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
        at java.net.Socket.connect(Socket.java:579)
        at java.net.Socket.connect(Socket.java:528)
        at java.net.Socket.(Socket.java:425)
        at java.net.Socket.(Socket.java:241)
        at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:257)
        at com.mysql.jdbc.MysqlIO.(MysqlIO.java:294)
        ... 15 more

Common Errors in JDK Installation 

SYMPTOM: Cannot compile Java program from the CMD shell (e.g., "javac Hello.java" does not work!)
ERROR MESSAGE: 'javac' is not recognized as an internal or external command, operable program or batch file.

PROBABLE CAUSES: The PATH environment variable, which maintains a list of search paths for executable
   programs (including "javac.exe"), does not include JDK's bin directory.
POSSIBLE SOLUTIONS:
   1) Start a CMD shell (click "Start" button ⇒ "run..." ⇒ enter "cmd") and issue a path command:
         prompt> path
         PATH=.......
   2) Check if it includes your JDK's "bin" directory. For example, suppose that your JDK is installed 
      in "c:\program files\java\jdk1.7.0", then PATH should include "c:\program files\java\jdk1.7.0\bin".
Otherwise, include JDK's bin directory in the PATH environment variable. Read "Step 3 of How to install JDK". ------------------------------------------------------------------------------------------------- SYMPTOM: Can compile but cannot run Java program from the CMD shell (e.g., "java Hello" does not work!) ERROR MESSAGE: Exception in thread "main" java.lang.NoClassDefFoundError: Hello PROBABLE CAUSES: 1) The Java class (in this example, Hello.class) is NOT in the current directory. 2) The CLASSPATH environment variable is set, but does not include the current directory ".". POSSIBLE SOLUTIONS: 1) Issue a "dir" command to list the contents of the current directory. Check that it contains the Java class to be run (e.g., Hello.class). You need to compile the source program (".java") to get the class file (".class"). 2) If the Java class is present in the current directory, issue a "set classpath" command to check its settings: prompt> set classpath CLASSPATH=....... If you receive the message "Environment variable CLASSPATH not defined" and your program is correct, I can't help you here. Otherwise, if the CLASSPATH is defined, for beginner, I suggest that you remove the CLASSPATH environment variable. From "Control Panel" ⇒ System ⇒ (Vista only) Advanced system settings ⇒ Switch to "Advanced" tab ⇒ Environment Variables ⇒ System variables (and also User variables) ⇒ Select variable "CLASSPATH" ⇒ Delete (Delete from both the System variables and User variables) 3) (For Advanced Users Only) If CLASSPATH is not set, it is defaulted to the current directory. However, if CLASSPATH is set, the current directory is NOT implicitly included. You can include the current directory (denoted by a single dot ".") in front of the existing class-paths. Read "Java Applications and Environment Variable" for more discussion on CLASSPATH.

Common Errors in MySQL Installation and Getting Started 

Common Problems in Starting the MySQL Server after Installation 
SYMPTOM: Cannot start MySQL server after installation
ERROR MESSAGE: [ERROR] Can't find message file 'x:\xxxxx\share\english\errmsg.sys'
PROBABLE CAUSES: Error in "basedir" option in the configuration file "my.ini".
POSSIBLE SOLUTIONS:
  1. Take note of your MySQL installed directory, e.g., d:\myproject\mysql.
  2. Goto the MySQL installed directory, and check if "my.ini" exists.
  3. If you use NotePad, ensure that you save the configuration file as "my.ini", instead of "my.ini.txt".
     "my.ini.txt" has file type of "Text Document". "my.ini" has file type of "Configuration Settings".
     "Save As..." the file again by enclosing the filename "my.ini" with a pair of double quotes.
  4. Check the "basedir" and "datadir" options in "my.ini". Make sure that that path corresponds to your 
     MySQL installed directory. Use Unix-style forward slash '/' as the directory separator, instead of 
     Windows-style back slash '\'.
 
-------------------------------------------------------------------------------------------------
 
SYMPTOM: Cannot start MySQL server after installation
ERROR MESSAGE:
  [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
  .........
  [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
PROBABLE CAUSES: Error in "datadir" option in the configuration file "my.ini".
POSSIBLE SOLUTIONS: Check that "datadir" selects the "data" sub-directory of your MySQL installed directory, 
  e.g., datadir=d:/myproject/mysql/data
 
-------------------------------------------------------------------------------------------------
 
SYMPTOM: MySQL Server runs on TCP port 3306 (the MySQL default port number) instead of 8888 that was configured.
PROBABLE CAUSES: MySQL Server was not started with your customized "my.ini".
POSSIBLE SOLUTIONS:
  1. Take note of your MySQL installed directory, e.g., d:\myproject\mysql.
  2. Goto the MySQL installed directory, and check if "my.ini" exists.
  
-------------------------------------------------------------------------------------------------
 
SYMPTOM: Cannot start MySQL server.
ERROR MESSAGE:
  InnoDB: Operating system error number 32 in a file operation.
  InnoDB: The error means that another program is using InnoDB's files.
  InnoDB: This might be a backup or antivirus software or another instance of MySQL. 
  InnoDB: Please close it to get rid of this error.
PROBABLE CAUSES: You have already started an instance of MySQL.
POSSIBLE SOLUTIONS: Shutdown the previously-started MySQL.
  You may use "Task Manager" to cancel the "process" called "mysqld".
  [The proper way is to use "mysqladmin" to do a normal shutdown.]
Common Problems in Starting the "mysql" Client 
SYMPTOM: Cannot start mysql client
ERROR MESSAGE: ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)
PROBABLE CAUSES: 
  1. MySQL Server is NOT started, or
  2. The client was connecting to the wrong port number
POSSIBLE SOLUTIONS: 
  1. Check to make sure that the MySQL server has been started. 
     Note down the server's port number from the server's console.
  2. Check "my.ini", make sure that you have a [client] section with port=xxxx.
  3. Run a client with command "mysql -u root --port=xxxx" to specify the server's port number manually.
Common Problems in Using the "mysql" Client 
ERROR MESSAGE: ERROR 1046 (3D000): No database selected
PROBABLE CAUSES: The default database is not set
POSSIBLE SOLUTIONS: 
  1) Issue command "use database" to set the default database, or
  2) Use the fully-qualified name in the form of "databaseName.tableName".

Common Errors in Tomcat Installation 

Common Errors in Starting Tomcat after Installation 
SYMPTOM: Tomcat cannot start after installation. The Tomcat console flashed and disappeared.
POSSIBLE SOLUTIONS: 
  1. Check if you have already started a copy of Tomcat.
  2. You might made an error in your configuration files ("server.xml", "web.xml", "content.xml")
     Revert back to the original configuration files, and run with the original files 
     without changes. Tomcat shall start on port 8080.
  3. Check the Tomcat's log files, located at "<TOMCAT_HOME>\logs".
  4. start the tomcat in the debugging mode by running "catalina debug" and 
     type "run"  in the "jdb" prompt. Look for the error messages.

-------------------------------------------------------------------------------------------------
 
SYMPTOM: Tomcat cannot start after installation
ERROR MESSAGE: 
  1. Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
     At least one of these environment variable is needed to run this program
  2. JRE_HOME environment variable is not defined
POSSIBLE SOLUTIONS: 
  Define environment variable JAVA_HOME according to "Step 2 of the How to Install Tomcat".
  Check if JAVA_HOME is set to JDK installed directory. Check the spelling carefully.

-------------------------------------------------------------------------------------------------
 
SYMPTOM: Tomcat cannot start after installation
ERROR MESSAGE: java.lang.NoSuchMethodError: javax.servlet.ServletContext.getSessionCookieConfig()
    Ljavax/servlet/SessionCookieConfig;
PROBABLE CAUSES: This is a new method in Servlets 3.0 (which Tomcat 7 supports).
    There is a Servlets 2.x API is your CLASSPATH or JDK's extension directory.
POSSIBLE SOLUTIONS: Check your CLASSPATH. Remove servlet-api.jar from JDK's extension directory if any.
Common Errors in Accessing Tomcat
Common Error Messages:
  • (Firefox) Unable to Connect; (IE) Internet Explorer cannot display the webpage; (Chrome) Oops! Google Chrome could not connect to xxxx.
  • Error 404 File Not Found.
  • Error 500 Internal Server Error.
  • Error 505: GET (or POST) method not supported: Check you servlet to make sure that you have defined a doGet() (or doPost()) method.
Read "How to debug" section of "How to install Tomcat".

Common Errors in JDBC Programming 

Common Errors in JDBC Programming on MySQL 
SYMPTOM: Can compile the JDBC program but Runtime Error
ERROR MESSAGE: 
   (Windows) No suitable driver found
   (Mac/Linux) NullPointerException
PROBABLE CAUSES: MySQL JDBC Driver Connector/J was NOT (properly) installed.
POSSIBLE SOLUTION:
   1. Read "Step 8(a) of How to install MySQL" again, again and again... 
   2. Make sure that you copy the driver to the JDK's Extension directory.
   3. You may the following command to run your JDBC program:
      > java -cp .;path-to\mysql-connector-java-5.1.xx-bin.jar JdbcClassName
   4. For Tomcat, you may place the driver JAR-file in Tomcat's "lib" directory.
  
-------------------------------------------------------------------------------------------------
 
SYMPTOM: Can compile the JDBC program but Runtime Error
ERROR MESSAGE: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: 
   Communications link failure
PROBABLE CAUSES: 
   1. MySQL Server is NOT started, or
   2. The program was connecting to a wrong TCP port number or wrong hostname (or IP address)
      in your database-URL jdbc:mysql://localhost:port/studentdb.
POSSIBLE SOLUTION:
   1. Make sure that server has been started. Note down the server's port number 
      from the server's console.
   2. Check the database-URL's hostname and port number: jdbc:mysql://localhost:port/studentdb
   3. Run a MySQL client, issue command "status" to confirm the server's TCP port number.
   4. Run a mysql client, use "mysql -u root -p --port=xxxx" to specify the port number to
      confirm the server's port number.
  
-------------------------------------------------------------------------------------------------
 
SYMPTOM: Can compile the JDBC program but Runtime Error
ERROR MESSAGE: java.sql.SQLException: Access denied for user 'username'@'localhost' 
   (using password: YES)
PROBABLE CAUSES: Wrong username or password in statement:
   DriverManager.getConnection(databaseURL, username, password).
POSSIBLE SOLUTION: Obvious!
   
-------------------------------------------------------------------------------------------------
 
SYMPTOM: Can compile the JDBC program but Runtime Error
ERROR MESSAGE: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 
   Unknown database 'xxxx'
PROBABLE CAUSES: DriverManager.getConnection("jdbc:mysql://localhost:8888/xxxx", user, password) 
   specifies a database that does not exist in the server.
POSSIBLE SOLUTION: Create the database using a client, before running the Java program.
 
-------------------------------------------------------------------------------------------------
 
SYMPTOM: Can compile the JDBC program but Runtime Error
ERROR MESSAGE: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 
   Table 'xxxx.xxxx' doesn't exist
PROBABLE CAUSES: The SQL statement references a non-existence table.
POSSIBLE SOLUTION: Check your SQL statement and the database tables.
 
-------------------------------------------------------------------------------------------------
 
SYMPTOM: Can compile the JDBC program but Runtime Error
ERROR MESSAGE: java.sql.SQLException: Column 'xxx' not found.
PROBABLE CAUSES: The method ResultSet.getXxx(columnName) cannot locate 
   the requested columnName in the ResultSet.
POSSIBLE SOLUTION: Make sure that the column 'xxx' is included in the SELECT statement,
   so that it is included in the ResultSet. 
 
-------------------------------------------------------------------------------------------------
 
SYMPTOM: Can compile the JDBC program but Runtime Error
ERROR MESSAGE: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 
   You have an error in your SQL syntax; check the manual that corresponds to 
   your MySQL server version for the right syntax to use near .... at line x
PROBABLE CAUSES: Syntax error in your SQL statement.
POSSIBLE SOLUTION: Obvious!
 
-------------------------------------------------------------------------------------------------
 
SYMPTOM: Logical error in comparing floating point numbers for equality. 
   For example, "SELECT * FROM class101 WHERE gpa = 4.4" 
   yields empty set although there is a record with gpa=4.4.
PROBABLE CAUSES: 
   "gpa" has the type of FLOAT.
   Floating point numbers are not stored "accurately".
POSSIBLE SOLUTION: 
   Do not compare two floating point number for equality. 
   Instead, specify a range, e.g., "gpa > 3.9 AND gpa < 4.1"
 
-------------------------------------------------------------------------------------------------
 
SYMPTOM (NetBeans): I got this strange error running JDBC program on NetBeans.
ERROR MESSAGE: 
   The DriverManager.getConnection() method throws:
   com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error 
      in your SQL syntax; check the manual that corresponds to your MySQL server 
      version for the right syntax to use near '??' at line 1
POSSIBLE SOLUTION:
   The NetBeans project was using "UTF-16" as the default charset. Hence, it communicates
      with MySQL server using "UTF-16" character set.
   The problem solved by setting the default charset to an ASCII compatible charset
      such as "Latin-1" or "UTF-8" (Right-click on the project ⇒ Properties ⇒ Encoding)
Common Errors in JDBC Programming on MS Access 
SYMPTOM (Access 2007): Can compile the JDBC program but Runtime Error
ERROR MESSAGE: java.sql.SQLException: [Microsoft][ODBC Driver Manager] 
   Data source name not found and no default driver specified.
PROBABLE CAUSES: No such Data Source (ODBC) name in method 
   DriverManager.getConnection("jdbc:odbc:ODBCName");
POSSIBLE SOLUTION: Check your ODBC configuration (under control panel ⇒ ODBC).
 
-------------------------------------------------------------------------------------------------
 
SYMPTOM (Access 2007): Can compile the JDBC program but Runtime Error
ERROR MESSAGE: java.sql.SQLException: [Microsoft][ODBC Driver Manager] No data found
PROBABLE CAUSES: The ODBCName in method DriverManager.getConnection("jdbc:odbc:ODBCName") 
   does not SELECT a database.
POSSIBLE SOLUTION: Check your ODBC configuration (under control panel ⇒ ODBC).
 
-------------------------------------------------------------------------------------------------
 
SYMPTOM (Access 2007): Can compile the JDBC program but Runtime Error
ERROR MESSAGE: java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] 
   The Microsoft Office Access database engine cannot find the input table or query 'xxx'.  
   Make sure it exists and that its name is spelled correctly.
PROBABLE CAUSES: The SQL statement references a non-existence table.
POSSIBLE SOLUTION: Check your SQL statement and the database tables.
 
-------------------------------------------------------------------------------------------------
 
SYMPTOM (Access 2007): Can compile the JDBC program but Runtime Error
ERROR MESSAGE: java.sql.SQLException: Column not found.
PROBABLE CAUSES: The method ResultSet.getXxx(columnName) cannot locate 
   the requested columnName in the ResultSet.
POSSIBLE SOLUTION: Make sure that the column is included in the SELECT statement, 
   so that it is included in the ResultSet. 
 
-------------------------------------------------------------------------------------------------
 
SYMPTOM (Access 2007): Can compile the JDBC program but Runtime Error
ERROR MESSAGE: 
  [Microsoft][ODBC Microsoft Access Driver] Syntax error in FROM clause.
  [Microsoft][ODBC Microsoft Access Driver] Too few parameters.
  ....
PROBABLE CAUSES: Syntax error in the SQL statement.
POSSIBLE SOLUTION: Obvious!
 
-------------------------------------------------------------------------------------------------
 
SYMPTOM (Access 2007): Can compile the JDBC program but Runtime Error
ERROR MESSAGE: 
  [Microsoft][ODBC Microsoft Access Driver] SQL General Error.
PROBABLE CAUSES: This message is not clear, but most likly caused by inserting a record
  with duplicate primary key.
 
-------------------------------------------------------------------------------------------------
 
SYMPTOM (Access 2007): Can compile the JDBC program but Runtime Error
ERROR MESSAGE: 
  [Microsoft][ODBC Microsoft Access Driver] The number of fields are not the same as the ....
PROBABLE CAUSES: In the INSERT INTO tableName VALUES (...), you should have the same number
  of values as the number of columns.

Common Errors in Compiling Java Servlet 

SYMPTOM: Cannot compile Java Servlet
ERROR MESSAGE: 
  class xxxx is public, should be declared in a file named xxxx.java
CAUSES/SOLUTION:
  In Java, the filename must be the same as the classname with extension of ".java".
  For example, the class "HelloServlet" must be saved as "HelloServlet.java" - case-sensitive!
  
-------------------------------------------------------------------------------------------------
 
SYMPTOM: Cannot compile Java Servlet
ERROR MESSAGE: package javax.servlet does not exist
CAUSES/SOLUTION:
  The Java Servlet library is missing. Read "Step 6(a) of How to install Tomcat" 
  again, again and again....

Common Errors in using NetBeans 

SYMPTOM: Cannot display chinese characters and other Unicode characters in the NetBeans editor
ERROR MESSAGE: Chinese characters displayed as boxes or question marks in the NetBeans editor
CAUSES/SOLUTION:
  1. Check the character set. Right-click on the project ⇒ Property ⇒ "Source" node 
     ⇒ "Encoding" ⇒ Choose "UTF-8" or the desired Unicode charater sets.
  2. You also need to choose a font type that displays chinese or Unicode characters,
     such as "Monospace".
     In "Tools" menu ⇒ Options ⇒ Fonts & Colors ⇒ Syntax ⇒ default.
     If one font does not work, try another.

3 comments:

  1. It is amazing how fast we go from one computer to the next, needing more memory, more speed, but never finding enough.

    sql server error 10061

    ReplyDelete
  2. Google has disabled use of the Maps API for this application. The provided key is not a valid Google API Key, or it is not authorized for the Google Maps Javascript API v3 on this site. If you are the owner of this application, you can learn about obtaining a valid key here: https://developers.google.com/maps/documentation/javascript/tutorial#api_key


    I Am Getting This Error When I Load My Application I Am Using HTML 5 And JavaScript

    ReplyDelete
  3. Get in Touch with MySQL Technical Support for Common Errors When Using MySQL Programs | Cognegic
    At whatever point we are working with MySQL there might be odds of confronting some kind specialized blunders or glitches. These sorts of issues forestall you to work with your MySQL. Possibly you don't know that you will discover numerous specialized issues some of them are: "Secret key fizzled when entered intuitively", "Correspondence blunders and prematurely ended associations", "Table defilement issues" and some more. Ensure; in the event that you communicate with these issues than without quite a bit of stretch rapidly connect with Cognegic's MySQL Remote Support and MySQL Remote Service.
    For More Info: https://cognegicsystems.com/
    Contact Number: 1-800-450-8670
    Email Address- info@cognegicsystems.com
    Company’s Address- 507 Copper Square Drive Bethel Connecticut (USA) 06801

    ReplyDelete