Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ANT JDBC driver [com.mysql.jdbc.Driver] could not be loaded?

I decided I wanted to start learning about databasing, primarily with a focus on MySQL. I figured I'd follow this tutorial with high hopes of better understanding how these thing work and can be integrated into our programs. But I've ran into a small issue that I don't know how to bypass.

A couple of things:

  • Ant has been installed and appended to my Path Environment Variable.
  • I'm using the MySQL Community Edition database.
  • MySQL Connector J is the connector I've chosen to use. It has been appened to both my Path Environment Variable as well as denoted property of MYSQLDRIVER in my mysql-build-properties.xml file.

When I go to run the command ant create-mysql-database in my JDBCTutorial Directory it give me an error saying the following:

     C:\[LOCATION]\JDBCTutorial ant create-mysql-database
     BUILD FAILED
     C:\[LOCATION]\JDBCTutorial\build.xml:73: Class
      **Not Found: JDBC driver com.mysql.jdbc.Driver could not be loaded**

Looking in the build.xml file on line:73 I have the following:

70 <target name="create-mysql-database">
71    <sql driver="${DB.DRIVER}" url="${DB.URL.NEWDATABASE}" userid="${DB.USER}"
72         password="${DB.PASSWORD}" classpathref="CLASSPATH"
73         delimiter="${DB.DELIMITER}" autocommit="false" onerror="continue">
74      create database ${DB.SID};
75    </sql>
76 </target>  

The build.xml file uses a mysql-build-properties.xml file containing the following:

<project name="MySQL Properties" default="all" basedir=".">

  <property name="JAVAC"          value="C:\\Program Files (x86)\\Java\\jdk1.7.0_21\\bin\\javac"/>
  <property name="JAVA"           value="C:\\Program Files (x86)\\Java\\jdk1.7.0_21\\bin\\java" />
  <property name="PROPERTIESFILE" value="properties/mysql-sample-properties.xml"/>
  <property name="MYSQLDRIVER"    value="C:\\Program Files (x86)\\MySQL\\MySQL Connector J\\mysql-connector-java-5.1.29-bin.jar"/>

  <path id="CLASSPATH">
    <pathelement location = "classes"/>
    <pathelement location = "${MYSQLDRIVER}"/>
    <pathelement location = "lib/JDBCTutorial.jar"/>
  </path>

  <property name="DB.VENDOR"          value="mysql"/>
  <property name="DB.DRIVER"          value="com.mysql.jdbc.Driver"/>
  <property name="DB.HOST"            value="localhost"/>
  <property name="DB.PORT"            value="3306"/>
  <property name="DB.SID"             value="testdb"/>
  <property name="DB.URL.NEWDATABASE" value="jdbc:mysql://${DB.HOST}:${DB.PORT}/?allowMultiQueries=true"/>
  <property name="DB.URL"             value="jdbc:mysql://${DB.HOST}:${DB.PORT}/${DB.SID}?allowMultiQueries=true"/>
  <property name="DB.USER"            value="root"/>
  <property name="DB.PASSWORD"        value="root"/>
  <property name="DB.DELIMITER"       value=";"/>

</project>

If anyone knows what I may have set up wrong please let me know.

like image 234
Tdorno Avatar asked Mar 06 '14 19:03

Tdorno


1 Answers

Your property MYSQLDRIVER should point to a JAR file. Shouldn't it be mysql-connector-java-5.1.29-bin.jar instead of mysql-connector-java-5.1.29-bin?

And maybe you can try to put this JAR into a location with a path which doesn't contain spaces in it.

like image 151
vanje Avatar answered Oct 18 '22 01:10

vanje