Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2011
    Rep Power

    Default Using mysql in Java on ubuntu


    I am new to Java programming language. I am studying from these from Java server programming from Black book.

    I am not getting this example basically the first part for registering the driver object with DriverManager class.

    Java Code:
    package com.kogent.jdbc;
    import java.sql.CallableStatement;
    import java.sql.Connection;
    import java.sql.DriverManager;
    public class CallableStatementEx1 {
    	private static final String url = "jdbc:mysql://localhost";
    	private static final String user = "root";
    	private static final String password = "v";
    	public static void main(String[] args) throws Exception {
    		Connection con = DriverManager.getConnection(url, user, password);
    		// Get CallableStatement
    		CallableStatement cs = con.prepareCall("{call createAccount (?, ?, ?, ?, ?, ?,)}");
    		// Set IN parameters
    		cs.setInt(1, 103);
    		cs.setInt(2, 9);
    		cs.setString(3, "Vivek");
    		cs.setInt(4, 10000);
    		cs.setString(5, "Delhi");
    		cs.setInt(6, 965068);
    		// Executing stored procedure
    		System.out.println("Account created");
    		// Close the connection
    when running this program. I am getting the below exceptions.

    Java Code:
    Exception in thread "main" java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    	at Method)
    	at java.lang.ClassLoader.loadClass(
    	at sun.misc.Launcher$AppClassLoader.loadClass(
    	at java.lang.ClassLoader.loadClass(
    	at java.lang.Class.forName0(Native Method)
    	at java.lang.Class.forName(
    	at com.kogent.jdbc.CallableStatementEx1.main(
    If have problem in understanding below lines of the program.
    url = "jdbc:mysql://localhost";
    Class.forName("com.mysql.jdbc.Driver").newInstance ();
    Any suggestion will be greatly helpful.

    Last edited by dearvivekkumar; 11-30-2011 at 04:47 AM.

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Rep Power

    Default Re: Using mysql in Java on ubuntu

    You have to add the mysql driver (jdbc driver) to your build path / classpath :-)
    MySQL :: Download Connector/J

  3. #3
    Join Date
    Nov 2011
    Rep Power

    Default Re: Using mysql in Java on ubuntu

    I have already added in the CLASSPATH env variable.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Rep Power

    Default Re: Using mysql in Java on ubuntu

    Never use the environment variable to hold your Java classpath.
    Use the -cp switch of either java (in this case) or javac to define the classpath, or define it in whatever IDE you are using.

    How are you running this?

Similar Threads

  1. Can't Install Ubuntu Natty Narwhal Java 7 JDK
    By kayve in forum New To Java
    Replies: 0
    Last Post: 09-16-2011, 10:45 PM
  2. Ubuntu, run executable file in java
    By felipin85 in forum New To Java
    Replies: 0
    Last Post: 05-11-2011, 01:31 PM
  3. Java TTS on Ubuntu with Festival
    By Desh Banks in forum Advanced Java
    Replies: 2
    Last Post: 01-06-2011, 01:09 AM
  4. setting classpath for java in ubuntu
    By kulangotski in forum Java Servlet
    Replies: 0
    Last Post: 01-03-2011, 03:18 AM
  5. mysql classpath ubuntu problem
    By munish in forum JDBC
    Replies: 18
    Last Post: 08-22-2010, 02:55 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts