Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Materia:
Estudiantes:
INGENIERÍA DE SISTEMAS
BOGOTÁ D.C.
2017
JAVA
Main
package clientes;
import java.util.Scanner;
public class Clientes {
public static void main(String[] args) {
Insertar Ins = new Insertar();
Scanner lector = new Scanner(System.in);
int Sel = 999;
do {
System.out.println("Seleccione una opcion: ");
System.out.println("1. Insertar"
switch(Sel){
case 1:
Ins.Insertar();
break;
}
}while (Sel != 0);
}
}
Conexión a la base de datos
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
public class Conexion {
String usr = "root";
String pwd = "";
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost/eurekabank";
Connection con = null;
public Connection Conexion(){
try{
Class.forName(driver);
con= DriverManager.getConnection(url, usr, pwd);
return con;
} catch(Exception ex){
ex.printStackTrace();
return con;
}
}
}
Insertar Datos del Cliente
public class Insertar extends Conexion {
PreparedStatement pstm = null;
ResultSet rs = null;
Scanner x = new Scanner(System.in);
Leer Read = new Leer();
String nombre , id, correo;
int telefono, Sel = 999;
public void Insertar(){
do{
try{
Class.forName(driver);
con = DriverManager.getConnection(url,usr,pwd);
this.con.createStatement();
System.out.println("Complete los siguientes campos:");
System.out.print("Nombre: ");
nombre = x.nextLine();
System.out.print("identificación: ");
id = x.nextLine();
System.out.print("Telefono: ");
telefono = x.nextInt();
x.nextLine();
System.out.print("Correo: ");
correo = x.nextLine();
System.out.println("");
String sql="insert into cliente values (null, '" + nombre + "', '" + id + "', '" + telefono + "',
'"+ correo +"')";
pstm = con.prepareStatement(sql);
pstm.executeUpdate(sql);
Read.Leer();
}
catch(Exception ex){
ex.printStackTrace();
throw new RuntimeException(ex);
}
finally{
try{
if( rs != null ) rs.close();
if( pstm != null) pstm.close();
if( con != null) con.close();
}
catch(Exception ex)
{
ex.printStackTrace();
throw new RuntimeException(ex);
}
}
VISUAL BASIC
Conexión Base de Datos
Module Funciones
Clase Cliente
Public Class Cliente
Main (Formulario)
Private Sub Binsertar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Binsertar.Click
Dim consecutivo, telefono As Integer
Dim nombre, correo, id As String
nombre = Val(Me.TBinsertarnombre.Text)
id = Val(Me.TBinsertarid.Text)
telefono = Val(Me.TBinsertartelefono.Text)
correo = Me.TBinsertarcorreo.Text
cliente1.Insertar()
End Sub