Well I'm working on a GNU/Linux machine and I'm still learning how to connect to my database
I've got the Connector/J File downloaded and edited my CLASSPATH, here's the reusult of echoing the path
/home/user/Connector-J/mysql-connector-java-5.1.30/mysql-connector-java-ver-bin.jar:
I also have my SQL File.. let's say: sqlfile.sql
Threw the documentation and while searching I found how I should connect to the Connector.. My question is: where should I put my SQL file?
Also, Here's a piece of code I found that is used to connect, is it right?
String userName = "root";
String password = "password";
String url = "jdbc:mysql://localhost/somefile";
Class.forName ("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection (url, userName, password);
System.out.println ("Database connection established");
To build an application that connects to a database, you will need:
Your code is only creating connection. Even that, the url looks incorrect. The "somefile" should be replaced with the name of database schema you want to connect to.
To interact with database, creating connection is still far from done. To read, insert, update, delete, etc records from/to database, you need to create statement object by passing your SQL query. The SQL queries should not be put in a file, but written in your code instead. Complete JDBC tutorial is here: http://docs.oracle.com/javase/tutorial/jdbc/