Mencoba Menghubungkan Java dengan MySql pada netbeans
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication1;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
/**
*
* @author acer
*/
public class JavaApplication1 {
public static Connection con;
public static Statement stm;
public static void main(String[] args) {
try {
String url ="jdbc:mysql://localhost/tutorial";
String user="root";
String pass="";
Class.forName("com.mysql.jdbc.Driver");
con =DriverManager.getConnection(url,user,pass);
stm = con.createStatement();
System.out.println("koneksi berhasil;");
} catch (Exception e) {
System.err.println("koneksi gagal" +e.getMessage());
}
}
}
Komentar
Posting Komentar