LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-20-2012, 03:37 AM   #1
shifter
Member
 
Registered: May 2006
Distribution: Slackware, DragonFly
Posts: 233

Rep: Reputation: 30
connection Java/MySQL


Hi all, I'm writing my first java program on Ubuntu system.
I installed on Ubuntu system the libmysql-java package, I writed my program and then I compiled it, but I have the following message in running it:

Code:
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 Primo.main(Primo.java:9)
My program is the following:

Code:
import java.sql.*;

class Primo {

  public static void main(String[] args) {
    try {
      Class.forName("com.mysql.jdbc.Driver");
      Connection conn = DriverManager.getConnection("dbname", "root", "mypasswd");
      Statement cmd = conn.createStatement();
      String query = "SELECT * from mytable;";
      ResultSet res = cmd.executeQuery(query);
      while (res.next()) {
        System.out.println(res.getString("Codice"));
      }
    }
    catch (ClassNotFoundException e) {
      e.printStackTrace();
    }
    catch (SQLException e) {
      e.printStackTrace();
    }
  }

}
Where is the problem?


Thanks in advance for answers.
 
Old 10-20-2012, 06:22 AM   #2
SecretCode
Member
 
Registered: Apr 2011
Location: UK
Distribution: Kubuntu 11.10
Posts: 562

Rep: Reputation: 102Reputation: 102
Have you included the MySQL Java Connector .jar in your project's properties? (If you're using Eclipse, project properties > Java Build Path > Libraries > Edit...)
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
java + connection to mysql linux_ub Programming 5 03-04-2012 10:59 AM
Mysql and mysql java connector, connection refused arubin Slackware 3 03-29-2008 01:41 AM
Using Same MySQL Connection for 2 Java Appls MRMadhav Programming 4 09-11-2007 07:42 PM
java and mysql connection difficulties mrj Linux - Software 1 07-04-2007 02:24 AM
MySQL/Java connection problem hudy Programming 3 06-23-2004 08:40 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:31 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration