Sei sulla pagina 1di 1

/*

* To change this template, choose Tools | Templates


* and open the template in the editor.
*/
package koneksi2;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
/**
*
* @author SMKBN666
*/
public class insertdata {
void insert(String nama,String kelas) throws SQLException, ClassNotFoundExceptio
n {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/
konek2","root","");
Statement stmt=con.createStatement();
stmt.executeUpdate("insert into contoh values (null,'"+nama+"','"+kelas+"'
)");
stmt.close();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws SQLException, ClassNotFoundExc
eption {
insertdata input = new insertdata();
input.insert("dian","XII2");
System.out.println("data berhasil diinput");
}
}

Potrebbero piacerti anche