Código:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try{
Connection conexion=DriverManager.getConnection("jdbc://localhost/base","root","");
Statment smt = conexion.createStatement();
//tomando las variables
id=Integer.parseInt(idField.getText());
nombre=nameField.getText();
//Insertando las variables
String sql="INSERT INTO regiones(id,nombre) VALUES("+id+","+nombre+")";
stm.execute(sql);
//terminando conexion
JOptionPane.showMessageDialog(null, "GUardado con Éxito", "Guardar",JOptionPane.PLAIN_MESSAGE);
conexion.close();
}
//Excepción
catch(SQLException ex){
resulSet rs =stm.executeQuery(sql);
while(rs.next()){
System.out.print(rs.getData(0));
//System.out.print(rs.getString("nombre");
}
}
Código:
public static void main(String args[])throws Exception{
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new simple().setVisible(true);
}
});
}