Hi
There is a problem in JDBC connectivity.I have downloaded the JDBC Connector/J for MySQL connectivity with java. I've changed the CLASSPATH environment variable, made changes in the code and tried and tested with several modifications. But it still doesn't work. Here is the source code.
import java.sql.*; public class Check { public static void main(String args[]) { Connection conn=null; try { String url="jdbc:mysql://localhost/example"; Class.forName("com.jdbc.mysql.Driver").newInstance(); conn=DriverManager.getConnection(url); System.out.println("Database connection established"); } catch(Exception e) { System.out.println("Cannot connect to server"); } finally { if(conn!=null) { try { conn.close(); System.out.println("Database connection terminated"); } catch(Exception e) { } } } } }
It compiles and displays "Cannot connect to database" when run on the command prompt.
Here are some specifications:
(1) My JDK is in C:\ drive
(2) MySQL is in Program Files.
(3) The Connector/J is in C:\jdk1.6.0_16\jre\lib\ext
The ext folder has the mysql-connector-java-5.1.10-bin.jar file.
Hence the CLASSPATH environment variable includes : C:\jdk1.6.0_16\jre\lib\ext\mysql-connector-java-5.1.10-bin.jar
Please help me with this so that I can move on...