I am very new to Java and am trying to learn how to connect and modify a MySQL database. Here is the connection script I am using to try to create a table in an existing database.
What am I doing wrong? I don't get any errors (I don't get any output at all).
I am thinking I am not including the connection library properly (although no complaints from XCode (I am using a Mac). The MySQL Server I am attempting to connect with is not local.
Any help would be appreciated, and any advice on where to go to get insight into database connections with Java and MySQL would help. I am an experienced PHP, Javascript, Perl programmer, but Java is new to me.
LJ Wilson
My personal saying - Just remember, it can always get worse, and usually will.
What am I doing wrong? I don't get any errors (I don't get any output at all).
Code:
import java.sql.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class CreateCoffees {
public static void main(String args[]) {
String url = "jdbc:mysql:MyServerAddress/coffeebreak ";
//Connection con;
String createString;
createString = "create table COFFEES " +
"(COF_NAME VARCHAR(32), " +
"SUP_ID INTEGER, " +
"PRICE FLOAT, " +
"SALES INTEGER, " +
"TOTAL INTEGER)";
Statement stmt;
try {
Class.forName("com.mysql.jdbc.Driver");
} catch(java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try {
Connection conn = DriverManager.getConnection(url, "myUName", "MyPassword");
System.out.println("Connected");
stmt = conn.createStatement();
stmt.executeUpdate(createString);
stmt.close();
conn.close();
System.out.println("Connection Closed");
} catch(SQLException ex) {
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
}
}
I am thinking I am not including the connection library properly (although no complaints from XCode (I am using a Mac). The MySQL Server I am attempting to connect with is not local.
Any help would be appreciated, and any advice on where to go to get insight into database connections with Java and MySQL would help. I am an experienced PHP, Javascript, Perl programmer, but Java is new to me.
LJ Wilson
My personal saying - Just remember, it can always get worse, and usually will.