DB Name: MPG
table name: mpgdata
URL to access phpMyAdmin: 192.168.1.22/phpMyAdmin
Once I'm logged in at the top of the page (not in the URL bar) it says 127.0.0.1
//Establish database connection
public void connectDB() {
Connection conn = null;
String address = "jdbc:msql://127.0.0.1/";
String name = "MPG";
String driver = "com.mysql.jdbc.Driver";
String username = "user";
String password = "user";
try {
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(address+name, username, password);
try {
//Write data to table
Statement st = conn.createStatement();
int val = st.executeUpdate("Insert into mpgdata (dbDate, dbStation, dbOctane, dbMiles, dbGallons, dbMPG) values ("+strStation+","+strOctane+", "+strMiles+", "+strGallons+", "+strMPG+")");
JOptionPane.showMessageDialog(null, "Record has been added!");
} catch (SQLException s) {
JOptionPane.showMessageDialog(null, "Data has NOT been written to table.");
};
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "You have received a Database Connection Error.");
}
}
When I try to run this it says "You have received a Database Connection Error.". My gut tells me it is the address/url of the database causing the issue because that's the only thing I'm really unsure of.

New Topic/Question
Reply



MultiQuote








|