jdbc driver install location?

Joined
Jun 27, 2011
Messages
7
Reaction score
0
Points
1
Trying to install mysql-connector-java-5.1.16. I set my CLASSPATH but I do not know what location to place certain files. Install instructions seem pretty vague. Originally I thought all I needed to do was set the CLASSPATH, but after trying to run my code, don't think the driver is in right location to be loaded.

Here is my java code for connecting to a database...

import java.sql.*;

public class Query
{
public static void main(String[] args)
{
try
{
Statement stmt;
Class.forName("com.mysql.jdbc.Driver"); //Line 10
String url =
"jdbc:mysql://localhost:3306/db_test";
Connection con =
DriverManager.getConnection(url, "root", "***");

try
{
stmt = con.createStatement();
stmt.executeUpdate("CALL add_item('carrots')");
}
catch(SQLException s)
{
System.out.println(s);
System.out.println("procedure did not execute");
}

con.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}

When executed get this error:

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver //on Line 10

Thinking because I do not have driver files in right location...

If anyone has installed this driver before on a mac, any 'play by play' on how to get this working would be great!

Thanks
 
OP
M
Joined
Jun 27, 2011
Messages
7
Reaction score
0
Points
1
Help: Anyone who knows jdbc driver install

Hello, I posted the following in 'operating systems' but thought I would put it here as well, trying to find someone who knows how to install a jdbc driver on mac. Having problems getting some java code to work. Anyway, here is the original post:

Post title: jdbc driver install location?

Trying to install mysql-connector-java-5.1.16. I set my CLASSPATH but I do not know what location to place certain files. Install instructions seem pretty vague. Originally I thought all I needed to do was set the CLASSPATH, but after trying to run my code, don't think the driver is in right location to be loaded.

Here is my java code for connecting to a database...

import java.sql.*;

public class Query
{
public static void main(String[] args)
{
try
{
Statement stmt;
Class.forName("com.mysql.jdbc.Driver"); //Line 10
String url =
"jdbc:mysql://localhost:3306/db_test";
Connection con =
DriverManager.getConnection(url, "root", "***");

try
{
stmt = con.createStatement();
stmt.executeUpdate("CALL add_item('carrots')");
}
catch(SQLException s)
{
System.out.println(s);
System.out.println("procedure did not execute");
}

con.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}

When executed get this error:

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver //on Line 10

Thinking because I do not have driver files in right location...

If anyone has installed this driver before on a mac, any 'play by play' on how to get this working would be great!

Thanks
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
Merged and moved threads. Please don't crosspost and note that The Lounge is for off-topic discussion.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top