Skip to content

Instantly share code, notes, and snippets.

@roypurbo
Last active December 16, 2015 11:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roypurbo/20f7e9158b668bf91112 to your computer and use it in GitHub Desktop.
Save roypurbo/20f7e9158b668bf91112 to your computer and use it in GitHub Desktop.
Koneksi
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package koneksi;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
/**
*
* @author phantom
*/
public class Koneksi {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws ClassNotFoundException {
// TODO code application logic here
Connection conn = null;
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost:3306/db_koneksi"; // sesuaikan dengan nama database anda
String user = "root"; // user mysql anda
String pass = ""; // passowrd mysql
try {
Class.forName(driver);
conn = DriverManager.getConnection(url,user,pass);
System.out.println("Koneksi Berhasil");
} catch (SQLException e) {
System.out.println("SQLException: "+e.getMessage());
System.out.println("SQLState: "+e.getSQLState());
System.out.println("VendorError: "+e.getErrorCode());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment