I have made this connection:
if (txtUsername.getText().equals("ok") && pwd.getText().equals("ok")) {
String driverName = "com.mysql.jdbc.Driver"; // Start JDBC
String dbURL = "jdbc:mysql://myserver.com:3306/programm_java";
String userName = "programm_java"; // windows user
String userPwd = "12345"; // windows login password
Connection dbConn;
try {
Class.forName(driverName);
dbConn = DriverManager.getConnection(dbURL, userName, userPwd);
System.out.println("Connection Successful!");
lb1.setText("enstablished");
} catch (Exception e) {
lb1.setText(e.getLocalizedMessage());
}
The above code is just a connection test.IT's not working and cant enstablish a connection....How am I supposed to do this :(.
Also how can I execute a SQL query?I didn't managed to find a way...I need to check if the users input match a SQL record,but where and how am I supposed to write the query?! :confused:
PS - I also tried:
private void startConnection()
{
Connection conn = null;
String url = "jdbc:mysql://www.mysqlURL.net:3306";
String dbName = "programm_java";
String driver = "com.mysql.jdbc.Driver";
String userName = "programm_java";
String password = "12345";
try {
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url+dbName,userName,password);
lb1.setText("Connected to the database");
conn.close();
lb1.setText("Disconnected from database");
} catch (Exception e) {
lb1.setText("NO CONNECTION =(");
}
}
It always sais NO CONNECTION :DPlease help!!!
Any help is highly appreciated!
Edited by alex1, 21 January 2012 - 04:55 AM.


Sign In
Create Account


Back to top










