1: download that msi you referred to @ http://dev.mysql.com/downloads/connector/j/
2: run it. after it runs the install app vanishes, not exactly a roadmap for success for an install routine
- from the root of c:\ I issue:
dir mysql-connector-java-5.1.36-bin.jar /s
I let it run the whole way thru to confirm I didn't already have it installed elsewhere
C:\>dir mysql-connector-java-5.1.36-bin.jar /s
Directory of C:\Program Files (x86)\MySQL\MySQL Connector J
06/19/2015 09:26 PM 972,009 mysql-connector-java-5.1.36-bin.jar
1 File(s) 972,009 bytes
Total Files Listed:
1 File(s) 972,009 bytes
Seems consistent with my 5.1.35 filesize I was using before stumbling into your question
Btw, the above MySql Connect J folder date was just created so I am sure that was from the install
I copy (not moving it) it to my c:\javadeps
folder.
I have a database called so_gibberish
, and a table called thingws
with 3 rows in it
source code (myTest.java):
I poached this stub off the internet as I am mostly a scala/jvm programmer. So please forgive. But it works.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
public class myTest {
public static void main(String[] args) {
Connection con = null;
Statement st = null;
ResultSet rs = null;
String url = "jdbc:mysql://localhost:3306/so_gibberish"; // **** MODIFY db name @ end
String user = "stan"; // **** MODIFY
String password = "stan_password"; // **** MODIFY
try {
con = DriverManager.getConnection(url, user, password);
st = con.createStatement();
System.out.println("------------------------------");
rs = st.executeQuery("select version()");
if (rs.next()) {
System.out.println(rs.getString(1));
System.out.println("------------------------------");
}
rs = st.executeQuery("select id,myCode from thingws");
while (rs.next()) {
System.out.println(rs.getInt(1)+": "+rs.getString(2));
}
System.out.println("------------------------------");
} catch (SQLException ex) {
Logger lgr = Logger.getLogger(myTest.class.getName());
lgr.log(Level.SEVERE, ex.getMessage(), ex);
} finally {
try {
if (rs != null) {
rs.close();
}
if (st != null) {
st.close();
}
if (con != null) {
con.close();
}
} catch (SQLException ex) {
Logger lgr = Logger.getLogger(myTest.class.getName());
lgr.log(Level.WARNING, ex.getMessage(), ex);
}
}
}
}
I will save it in C:\dev\java8\quick_java_mysql_test
- compile and run (when you run it, it does a query for the mysql version, then a query on that table getting 3 rows)
c:\dev\java8\quick_java_mysql_test>javac myTest.java
c:\dev\java8\quick_java_mysql_test>java -cp .;c:\javadeps\mysql-connector-java-5.1.36-bin.jar myTest
output is:
------------------------------
5.6.24-log
------------------------------
1: C938CA
2: XYZ123
3: XYZPDQ
------------------------------
It is common to have a dependencies folder for jars at the project-level, such as a dep
directory under the project folder.
Though I have that same jar file in it, it is not referenced, as seen in the -cp directive in step 7
that picks the jar up in c:\javadeps
plan your strategy according, and good luck