Friday, April 15, 2011

Published 4/15/2011 by with 0 comment

java.sql.SQLException: Access denied for user

The full error message may be : java.sql.SQLException: Access denied for user 'root'@'localhost' (using password : YES) or java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: NO) When we try to connect to a database through JDBC with wrong username or password - we see this error message. See the sample code below: Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/DatabaseName","root","mypassword"); In...
Read More
    email this       edit
Published 4/15/2011 by with 0 comment

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database

Trying to connect to a MySQL server from Java? But seeing the error "Unknown database"? The reason is that the database does not exist in the MySQL server. You might have accidentally misspelled the database name in the JDBC connection url. See the code below: Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/sales","username","password"); Here sales is the database...
Read More
    email this       edit
Published 4/15/2011 by with 0 comment

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

This error message may include the following text also: "The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server." When we try to connect to a MySQL server "Communications link failure" error may occur for any of the following errors: i) MySQL server is not running. Check for this and run the sever if it is stopped. ii)...
Read More
    email this       edit
Published 4/15/2011 by with 2 comments

ClassNotFoundException: com.mysql.jdbc.Driver

This error occurs when the required JDBC driver file is not in the CLASSPATH. Also, if the driver name is not correct ClassNotFoundException occurs. To solve this problem, at first check the driver name; if the driver name is correct, do one of the followings as per requirement. i) Add an entry for the driver file (mysql-connector-java-5.1.10.jar, for example) in the CLASSPATH variable. or ii)...
Read More
    email this       edit

Sunday, April 10, 2011

Published 4/10/2011 by with 1 comment

call to super must be first statement in constructor

The error message is very clear actually: i) We can call super in the constructor of a subclass ii) If we call super in the constructor of a subclass, it must be the first statement in that constructor; i.e, before writing any other statement we call to super must be made. It is mentionable that, super(parameters) calls the constructor of the super class. See the code below: The super class... public...
Read More
    email this       edit

Friday, October 30, 2009

Published 10/30/2009 by with 0 comment

java.lang.ArrayIndexOutOfBoundsException

It's a very common runtime error message or exception we face when we use array wrongly. Very specifically this exception is thrown to indicate that an array has been accessed with an illegal index (location / position / subscript). The index is either negative or greater than or equal to the size of the array. See the following code: int data[]={5,7,18,21,27,15,3}; //show the array elementsfor(int...
Read More
    email this       edit
Published 10/30/2009 by with 0 comment

array dimension missing

'array dimension missing' is shown when the array size is not specified while allocating memory for the array or creating an array. See below: int data[ ]=new int[ ]; See that, blank [ ] is given in new int[ ]. We must give an int as the size of the array. Memory will be allocated for the array according to the given int within the [ ] as below: int data[]=new int[...
Read More
    email this       edit
Published 10/30/2009 by with 7 comments

illegal initializer

You may see this error for writing wrong expression to initialize an array. See the code below: int data={42,15,27,20,19}; If you compile this, you will see the following error message: illegal initializer for intint data={42,15,27,20,19}; ^ Here the array is not declared properly as we have not put [ ] for declaring the array. The correct code is: int data[ ]={42,15,27,20,19}; or int[ ]...
Read More
    email this       edit
Published 10/30/2009 by with 1 comment

incompatible types

1. Sometimes we may get the following error message in an 'if' (selection) structure. incompatible typesfound : intrequired: boolean This is because, we have not specified a boolean expression as the condition of the 'if'; instead we might have written such an expression which is may be int, float, String or other types but not boolean. See the code below: int a=10,b=10; if(a=b){ System.out.println("a...
Read More
    email this       edit

Friday, August 28, 2009

Published 8/28/2009 by with 0 comment

cyclic inheritance involving ...

public class Person extends Employee{ private String firstName; private String lastName; public Person(String firstName,String lastName) { this.firstName=firstName; this.lastName=lastName; } } Person is a class which inherits Employee and see the code below where Employee also inherit the Class Person. public class Employee extends Person{ private double salary; public Employee(String firstName,String...