Altas, Bajas y Modificaciones de Registros en tabla MYSQL



Similar documents
Apéndice C: Código Fuente del Programa DBConnection.java

Homework/Program #5 Solutions

Advanced Network Programming Lab using Java. Angelos Stavrou

11. Applets, normal window applications, packaging and sharing your work

DHBW Karlsruhe, Vorlesung Programmieren, Remote Musterlösungen

ICOM 4015: Advanced Programming

public class demo1swing extends JFrame implements ActionListener{

Using A Frame for Output

// Correntista. //Conta Corrente. package Banco; public class Correntista { String nome, sobrenome; int cpf;

Tema: Encriptación por Transposición

CSS 543 Program 3: Online Tic-Tac-Toe Game Professor: Munehiro Fukuda Due date: see the syllabus

COMPUTACIÓN ORIENTADA A SERVICIOS (PRÁCTICA) Dr. Mauricio Arroqui EXA-UNICEN

INTRODUCTION TO COMPUTER PROGRAMMING. Richard Pierse. Class 7: Object-Oriented Programming. Introduction

Appendix B Task 2: questionnaire and artefacts

Fondamenti di Java. Introduzione alla costruzione di GUI (graphic user interface)

How Scala Improved Our Java

DATABASDESIGN FÖR INGENJÖRER - 1DL124

Informatik II. // ActionListener hinzufügen btnconvert.addactionlistener(this); super.setdefaultcloseoperation(jframe.

ATSBA: Advanced Technologies Supporting Business Areas

Swing. A Quick Tutorial on Programming Swing Applications

CS 335 Lecture 06 Java Programming GUI and Swing

public class Craps extends JFrame implements ActionListener { final int WON = 0,LOST =1, CONTINUE = 2;

Part IV: Java Database Programming

Medientechnik. Übung MVC


Graphical User Interfaces

CS108, Stanford Handout #33. Sockets

Cours de Java. Sciences-U Lyon. Java - Introduction Java - Fondamentaux Java Avancé.

Estructura de aplicación en PHP para System i

How To Build A Swing Program In Java.Java.Netbeans.Netcode.Com (For Windows) (For Linux) (Java) (Javax) (Windows) (Powerpoint) (Netbeans) (Sun) (

Java is commonly used for deploying applications across a network. Compiled Java code

New Server Installation. Revisión: 13/10/2014

Nexawebホワイトペーパー. Developing with Nexaweb ~ Nexaweb to Improve Development Productivity and Maintainability

CS2506 Operating Systems II Lab 8, 8 th Tue/03 /2011 Java API

1. DESCRIPCIÓN DE WEB SERVICES DE INTERCAMBIO DE DATOS CON NOTARIOS

Callbacks. Callbacks Copyright 2007 by Ken Slonneger 1

Programming with Java GUI components

How To Create A Digital Signature Certificate

How to Convert an Application into an Applet.

GUIs with Swing. Principles of Software Construction: Objects, Design, and Concurrency. Jonathan Aldrich and Charlie Garrod Fall 2012

Propiedades del esquema del Documento XML de envío:

Principles of Software Construction: Objects, Design and Concurrency. GUIs with Swing. toad Spring 2013

Section 6 Spring 2013

1 Hour, Closed Notes, Browser open to Java API docs is OK

Programa llamado insert.html

5.17 GUI. Xiaoyi Jiang Informatik I Grundlagen der Programmierung

Prof. Edwar Saliba Júnior

file://c:\dokumente und Einstellungen\Marco Favorito\Desktop\ScanCmds.html

Java Appletek II. Applet GUI

Konzepte objektorientierter Programmierung

GOPAL RAMALINGAM MEMORIAL ENGINEERING COLLEGE. Rajeshwari nagar, Panapakkam, Near Padappai, Chennai

Brazil + JDBC Juin 2001, douin@cnam.fr

The Design and Implementation of Multimedia Software

Licence Informatique Année Exceptions

New words to remember

Java Classes. GEEN163 Introduction to Computer Programming

Final Project Report E3390 Electronic Circuit Design Lab. Electronic Notepad

public void setusername(string username) { this.username = username; } public void setname(string name) { this.name = name; }

Schema XML_PGE.xsd. element GrupoInformes. attribute XML_PGE.xsd unqualified qualified

JiST Graphical User Interface Event Viewer. Mark Fong

Essentials of the Java(TM) Programming Language, Part 1

Remote Method Invocation

Java GUI Programming. Building the GUI for the Microsoft Windows Calculator Lecture 2. Des Traynor 2005

New words to remember

POSIBILIDAD DE REALIZACIÓN DE PFC EN DELPHI (Luxembourg)

Using JML to protect Java code against SQL injection. Johan Janssen June 26, 2007

Introduction to the Java Programming Language

Extending Desktop Applications to the Web

Lösningsförslag till tentamen

DIPLOMADO DE JAVA - OCA

CERTIFICADO DE NIVEL INTERMEDIO IDIOMA: INGLÉS COMPRENSIÓN AUDITIVA

Apéndice C: Esquemas de la base de datos

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq

LOS ANGELES UNIFIED SCHOOL DISTRICT Policy Bulletin

Update a MS

Manejo Basico del Servidor de Aplicaciones WebSphere Application Server 6.0

CITY OF LAREDO Application for Certification of Compliance for Utility Connection ($ Application Fee Ordinance No.

Why Is This Important? Database Application Development. SQL in Application Code. Overview. SQL in Application Code (Contd.

Java and Databases. COMP514 Distributed Information Systems. Java Database Connectivity. Standards and utilities. Java and Databases

Essentials of the Java Programming Language

2. Installieren des MySQL Workbench (Version ) 3. Unter Database > Manage Connection folgende Werte eintragen

LAYOUT MANAGERS. Layout Managers Page 1. java.lang.object. java.awt.component. java.awt.container. java.awt.window. java.awt.panel

The Abstract Windowing Toolkit. Java Foundation Classes. Swing. In April 1997, JavaSoft announced the Java Foundation Classes (JFC).

Cambridge IGCSE.

N A T I O N A L M I S S I N G P E R S O N S P R O G R A M DNA

Verbos modales. In this class we look at modal verbs, which can be a tricky feature of English grammar.

JDBC. It is connected by the Native Module of dependent form of h/w like.dll or.so. ex) OCI driver for local connection to Oracle

Schueler-Organisiertes Lernen am Beispiel von Grafischen Benutzer-Schnittstellen in Java Tag der Offenen Tür - GTS 2008

An Android-based Instant Message Application

JIDE Action Framework Developer Guide

1.-Subject details Código Asignatura Créditos Idioma P NP Total Inglés I Inglés

Señal RS232. d. codevilla v1.0

PERSONAL INFORMATION / INFORMACIÓN GENERAL Last Name / Apellido Middle Name / Segundo Nombre Name / Nombre

WEB SERVICES WEB SERVICES

NAME IN WHICH BUSINESS IS OR WILL BE CONDUCTED NOMBRE EN EL CUAL EL NEGOCIO ES O SERA CONDOCIDO CITY CIUDAD STATE ESTADO ZIP CODIGO POSTAL

Using NetBeans IDE for Desktop Development. Geertjan Wielenga

FTPS - FTPSE. Objetivo:

Conexión SQL Server C#

CHALLENGE TO INSTRUCTIONAL AND LIBRARY MATERIAL

Organizational agility through project portfolio management. Dr Catherine P Killen University of Technology, Sydney (UTS)

Transcription:

Altas, Bajas y Modificaciones de Registros en tabla MYSQL 1. En MySql crear una base de datos de nombre EmpresaABC y dentro de ella la tabla Empleados con la siguiente estructura: DNI integer(8) Definir Indice Primary AYN char (40) DOMICILIO char (40) TELEFONO integer(10) 2. Crear un proyecto Java de nombre ABMEmpleados (recordar agregar MySql-connector Ver Cartilla). 3. Dentro de este proyecto agregar dos nuevos programas basados en JFrame con WindowsBuilder. El primer programa será AltaEmpleados.java y el segundo, BajaModifEmpleado.java CODIGO AltaEmpleados. import java.awt.eventqueue; import javax.swing.jframe; import javax.swing.jpanel; import javax.swing.border.emptyborder; import javax.swing.jlabel; import javax.swing.jtextfield; import javax.swing.jbutton; import java.awt.event.actionlistener; import java.awt.event.actionevent; import java.sql.connection; import java.sql.drivermanager; import java.sql.resultset; import java.sql.sqlexception; import java.sql.statement; import java.awt.color; import java.awt.font; import java.awt.component; public class AltaEmpleados extends JFrame { private JPanel contentpane; private JTextField tf2; private JTextField tf3; private JLabel labelresultado; private JTextField tf1; private JTextField tf4; /** * Launch the application. */ public static void main(string[] args) { EventQueue.invokeLater(new Runnable() { public void run() { AltaEmpleados frame = new AltaEmpleados(); frame.setvisible(true); catch (Exception e) { e.printstacktrace();

); /** * Create the frame. */ public AltaEmpleados() { getcontentpane().setlayout(null); setdefaultcloseoperation(jframe.exit_on_close); setbounds(100, 50, 606, 405); contentpane = new JPanel(); contentpane.setborder(new EmptyBorder(5, 5, 5, 5)); setcontentpane(contentpane); contentpane.setlayout(null); settitle("alta de Empleados"); JLabel lbldni = new JLabel("DNI:"); lbldni.setbounds(23, 42, 89, 14); contentpane.add(lbldni); tf1 = new JTextField(); tf1.setcolumns(10); tf1.setbounds(128, 42, 140, 20); contentpane.add(tf1); JLabel lbldescripcindelartculo = new JLabel("Apellido y Nombres:"); lbldescripcindelartculo.setbounds(23, 73, 95, 14); contentpane.add(lbldescripcindelartculo); tf2 = new JTextField(); tf2.setbounds(128, 73, 250, 20); contentpane.add(tf2); tf2.setcolumns(30); JLabel lblprecio = new JLabel("Domicilio:"); lblprecio.setbounds(23, 101, 95, 14); contentpane.add(lblprecio); tf3 = new JTextField(); tf3.setbounds(128, 101, 250, 20); contentpane.add(tf3); tf3.setcolumns(30); JLabel lbltelfono = new JLabel("Tel\u00E9fono:"); lbltelfono.setbounds(23, 130, 89, 14); contentpane.add(lbltelfono); tf4 = new JTextField(); tf4.setcolumns(20); tf4.setbounds(128, 130, 140, 20); contentpane.add(tf4);

JButton btnalta = new JButton("Guardar"); btnalta.addactionlistener(new ActionListener() { public void actionperformed(actionevent arg0) { labelresultado.settext(""); Connection conexion=drivermanager.getconnection("jdbc:mysql://localhost/empresaabc","root",""); Statement comando1=conexion.createstatement(); ResultSet registro = comando1.executequery("select * from empleados where dni="+tf1.gettext()); if (registro.next()==true) { // la condicion indica que el dni existe labelresultado.settext("ya existe el DNI!"); else { Statement comando2=conexion.createstatement(); comando2.executeupdate("insert into empleados (dni, ayn, domicilio, telefono) values ("+ tf1.gettext()+",'"+tf2.gettext()+"','"+tf3.gettext()+"',"+tf4.gettext()+")"); ); labelresultado.settext("se registraron los datos"); tf1.settext(""); tf2.settext(""); tf3.settext(""); tf4.settext(""); conexion.close(); catch(sqlexception ex){ btnalta.setbounds(128, 180, 89, 23); contentpane.add(btnalta); labelresultado = new JLabel("resultado"); labelresultado.setfont(new Font("Arial", Font.BOLD, 11)); labelresultado.setforeground(color.red); labelresultado.setbounds(272, 184, 229, 14); contentpane.add(labelresultado); cargardriver(); private void cargardriver() { Class.forName("com.mysql.jdbc.Driver"); catch(exception ex) {

CODIGO BajaModifEmpleados. import java.awt.eventqueue; import javax.swing.jframe; import javax.swing.jpanel; import javax.swing.border.emptyborder; import javax.swing.jlabel; import javax.swing.jtextfield; import javax.swing.jbutton; import java.awt.event.actionlistener; import java.awt.event.actionevent; import java.sql.connection; import java.sql.drivermanager; import java.sql.resultset; import java.sql.sqlexception; import java.sql.statement; import java.awt.color; import java.awt.font; public class BajaModifEmpleado extends JFrame { private JPanel contentpane; private JTextField tf2; private JTextField tf3; private JLabel labelresultado; private JTextField tf1; private JTextField tf4; private JButton btnborrar, btnmodificar, btnbuscar; /** * Launch the application. */ public static void main(string[] args) { EventQueue.invokeLater(new Runnable() { public void run() { BajaModifEmpleado frame = new BajaModifEmpleado(); frame.setvisible(true); catch (Exception e) { e.printstacktrace(); ); /**

* Create the frame. */ public BajaModifEmpleado() { getcontentpane().setlayout(null); setdefaultcloseoperation(jframe.exit_on_close); setbounds(100, 50, 606, 405); contentpane = new JPanel(); contentpane.setborder(new EmptyBorder(5, 5, 5, 5)); setcontentpane(contentpane); contentpane.setlayout(null); settitle("baja Modificacion de Empleados"); JLabel lbldni = new JLabel("DNI:"); lbldni.setbounds(23, 42, 89, 14); contentpane.add(lbldni); tf1 = new JTextField(); tf1.setcolumns(10); tf1.setbounds(128, 42, 140, 20); contentpane.add(tf1); JLabel lbldescripcindelartculo = new JLabel("Apellido y Nombres:"); lbldescripcindelartculo.setbounds(23, 73, 95, 14); contentpane.add(lbldescripcindelartculo); tf2 = new JTextField(); tf2.setbounds(128, 73, 250, 20); contentpane.add(tf2); tf2.setcolumns(30); JLabel lblprecio = new JLabel("Domicilio:"); lblprecio.setbounds(23, 101, 95, 14); contentpane.add(lblprecio); tf3 = new JTextField(); tf3.setbounds(128, 101, 250, 20); contentpane.add(tf3); tf3.setcolumns(30); JLabel lbltelfono = new JLabel("Tel\u00E9fono:"); lbltelfono.setbounds(23, 130, 89, 14); contentpane.add(lbltelfono); tf4 = new JTextField(); tf4.setcolumns(20); tf4.setbounds(128, 130, 140, 20); contentpane.add(tf4); labelresultado = new JLabel("resultado"); labelresultado.setfont(new Font("Arial", Font.BOLD, 11)); labelresultado.setforeground(color.red);

labelresultado.setbounds(130, 172, 229, 14); contentpane.add(labelresultado); btnborrar = new JButton("Borrar"); btnborrar.addactionlistener(new ActionListener() { public void actionperformed(actionevent arg0) { labelresultado.settext(""); Connection conexion=drivermanager.getconnection("jdbc:mysql://localhost/empresaabc","root",""); Statement comando=conexion.createstatement(); int cantidad = comando.executeupdate("delete from empleados where dni="+tf1.gettext()); if (cantidad==1) { tf1.settext(""); tf2.settext(""); tf3.settext(""); tf4.settext(""); labelresultado.settext("se borro el empleado"); else { labelresultado.settext("no existe el DNI"); conexion.close(); catch(sqlexception ex){ ); btnborrar.setbounds(23, 214, 133, 23); contentpane.add(btnborrar); btnborrar.setenabled(false); //... btnmodificar = new JButton("Modificar"); btnmodificar.addactionlistener(new ActionListener() { public void actionperformed(actionevent e) { labelresultado.settext(""); Connection conexion=drivermanager.getconnection("jdbc:mysql://localhost/empresaabc","root",""); Statement comando=conexion.createstatement(); int cantidad = comando.executeupdate("update empleados set ayn='" + tf2.gettext() + "'," + "domicilio= '" + tf3.gettext() + "'," + "telefono=" + tf4.gettext() + " where dni="+tf1.gettext()); if (cantidad==1) {

labelresultado.settext("se modifico el registro del empleado"); else { labelresultado.settext("no existe el DNI"); conexion.close(); catch(sqlexception ex){ ); btnmodificar.setbounds(166, 214, 140, 23); contentpane.add(btnmodificar); btnmodificar.setenabled(false); //... JButton btnbuscar = new JButton("Buscar"); btnbuscar.addactionlistener(new ActionListener() { public void actionperformed(actionevent arg0) { labelresultado.settext(""); Connection conexion=drivermanager.getconnection("jdbc:mysql://localhost/empresaabc","root",""); Statement comando1=conexion.createstatement(); tf2.settext(""); tf3.settext(""); tf4.settext(""); ResultSet registro = comando1.executequery("select * from empleados where dni="+tf1.gettext()); if (registro.next()==false) { // la condicion indica que el dni NO existe labelresultado.settext("el DNI No EXISTE!"); else { labelresultado.settext("el DNI EXISTE..."); tf2.settext(registro.getstring("ayn")); tf3.settext(registro.getstring("domicilio")); tf4.settext(registro.getstring("telefono")); btnborrar.setenabled(true); btnmodificar.setenabled(true); conexion.close(); catch(sqlexception ex){

); btnbuscar.setbounds(289, 38, 89, 23); contentpane.add(btnbuscar); cargardriver(); private void cargardriver() { Class.forName("com.mysql.jdbc.Driver"); catch(exception ex) {