Sabtu, 30 Oktober 2010

SIMPLE KONEKSI JDBC

package JavaConnection;

import java.sql.*;

public class MetodeInsert {
private Connection conect=null;
public MetodeInsert(String username, String password){
String insert = "insert into Daftar values('"+username+"','"+password+"')";

Statement state=null;
try {
Class.forName("com.mysql.jdbc.Driver");
}ca
tch(ClassNotFoundException ex){
ex.printStackTrace();
}
try {

conect = DriverManager.getConnection("jdbc:mysql://localhost:3306/Dataman","root","c-net");
state = conect.createStatement(); state.executeUpdate(insert); state.close(); }catch(SQLException ex){
ex.printStackTrace();
}
}

}


package JavaConnection;

import java.io.*;

public class Main {

public static void main(String[]args)throws Exception{
BufferedReader bufer = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Masukan username :");
String nama = bufer.readLine();
System.out.print("Masukan Password :");
String pass = bufer.readLine();
MetodeInsert insert = new MetodeInsert(nama, pass);

}
}

Tidak ada komentar: