Skip to content

Instantly share code, notes, and snippets.

@hasayvaz
Last active December 14, 2015 10:08
Show Gist options
  • Save hasayvaz/5069784 to your computer and use it in GitHub Desktop.
Save hasayvaz/5069784 to your computer and use it in GitHub Desktop.
connect to remote MySQL database with java
import java.sql.*;
public class Mysql {
public static void main(String[] args) {
System.out.println("MySQL connect example.");
Connection conn = null;
String url = "jdbc:mysql://localhost/";
String dbname = "telrehberi";
String driver = "com.mysql.jdbc.Driver";
String username = "telrehberi";
String password = "123";
try {
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url+dbname, username, password);
System.out.println("Connected to the database");
conn.close();
System.out.println("Disconnected from database");
} catch (Exception e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment