Results 1 to 4 of 4
Thread: Using mysql in Java on ubuntu
- 11-30-2011, 03:29 AM #1
Member
- Join Date
- Nov 2011
- Posts
- 2
- Rep Power
- 0
Using mysql in Java on ubuntu
Hi,
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.
when running this program. I am getting the below exceptions.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 { Class.forName("com.mysql.jdbc.Driver").newInstance(); 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 cs.execute(); System.out.println("Account created"); // Close the connection con.close(); } }
If have problem in understanding below lines of the program.Java Code:Exception in thread "main" java.lang.ClassNotFoundException: com.mysql.jdbc.Driver at java.net.URLClassLoader$1.run(URLClassLoader.java:217) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:205) at java.lang.ClassLoader.loadClass(ClassLoader.java:321) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294) at java.lang.ClassLoader.loadClass(ClassLoader.java:266) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:186) at com.kogent.jdbc.CallableStatementEx1.main(CallableStatementEx1.java:13)
url = "jdbc:mysql://localhost";
Class.forName("com.mysql.jdbc.Driver").newInstance ();
Any suggestion will be greatly helpful.
Thanks!Last edited by dearvivekkumar; 11-30-2011 at 03:47 AM.
- 11-30-2011, 07:12 AM #2
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
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
- 11-30-2011, 08:10 AM #3
Member
- Join Date
- Nov 2011
- Posts
- 2
- Rep Power
- 0
Re: Using mysql in Java on ubuntu
I have already added in the CLASSPATH env variable.
- 11-30-2011, 09:36 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Similar Threads
-
Can't Install Ubuntu Natty Narwhal Java 7 JDK
By kayve in forum New To JavaReplies: 0Last Post: 09-16-2011, 09:45 PM -
Ubuntu, run executable file in java
By felipin85 in forum New To JavaReplies: 0Last Post: 05-11-2011, 12:31 PM -
Java TTS on Ubuntu with Festival
By Desh Banks in forum Advanced JavaReplies: 2Last Post: 01-06-2011, 12:09 AM -
setting classpath for java in ubuntu
By kulangotski in forum Java ServletReplies: 0Last Post: 01-03-2011, 02:18 AM -
mysql classpath ubuntu problem
By munish in forum JDBCReplies: 18Last Post: 08-22-2010, 01:55 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks