Last active
December 14, 2015 10:08
-
-
Save hasayvaz/5069784 to your computer and use it in GitHub Desktop.
connect to remote MySQL database with java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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