0% found this document useful (0 votes)
73 views2 pages

Program A Server

1. The document describes how to set up a MySQL database environment in Java, including installing Java, MySQL, and NetBeans, creating a database and tables, and inserting sample data. 2. It provides code for a JSP page that inserts data into the MySQL database via a Java class using JDBC. 3. The Java class contains a method to connect to the database and insert data using a prepared statement.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
73 views2 pages

Program A Server

1. The document describes how to set up a MySQL database environment in Java, including installing Java, MySQL, and NetBeans, creating a database and tables, and inserting sample data. 2. It provides code for a JSP page that inserts data into the MySQL database via a Java class using JDBC. 3. The Java class contains a method to connect to the database and insert data using a prepared statement.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Configurar el entorno 1. Instalar java ([Link]) 2. Instalar Netbeans ([Link]) 3. Descargar el mysql (versin no-install). Descomprimir mysql (mysql-noinstall-5.1.48-win32.

zip) 4. Arrancar bd: >cd c:\mysql\bin c:\mysql\bin>mysqld --console 5. Abrir otra consola de ms-dos y ejecutar lo siguiente para hacer el login C:\mysql\bin>mysql -u root

6. Crear bd y tablas mysql> create database personal; Query OK, 1 row affected (0.00 sec) mysql> use personal; Database changed mysql> create table persona(nombre varchar (30),apellidos varchar(90),password varchar(7)); mysql> insert into persona values('Ainhoa','Serna Nocedal','a1234'); Query OK, 1 row affected (0.00 sec) mysql> insert into persona values('Irati','Alustiza Sagarna','bZ1234'); Query OK, 1 row affected (0.02 sec) mysql> show tables; +--------------------+ | Tables_in_personal | +--------------------+ | persona | +--------------------+ 1 row in set (0.00 sec) mysql> desc persona; +-----------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------+-------------+------+-----+---------+-------+ | nombre | varchar(30) | YES | | NULL | | | apellidos | varchar(90) | YES | | NULL | | | password | varchar(7) | YES | | NULL | | +-----------+-------------+------+-----+---------+-------+ 3 rows in set (0.02 sec) mysql> select * from persona;

Crear la pgina HTML que ejecute el programa de insertar en la BD ([Link]).

<%@page contentType="text/html" pageEncoding="UTF-8" import="[Link]"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "[Link] <% if ([Link]("izena")!=null){ BD ob=new BD();

[Link]=[Link]("izena"); [Link]=[Link]("abizena"); [Link]=[Link]("password"); [Link](); } %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> </head> <body> <h1>Hello World!</h1> <form> Izena:<input type="text" name="izena" value="" /><br/> Abizena:<input type="text" name="abizena" value="" /><br/> Password:<input type="password" name="password" value="" /><br/> <input type="submit" value="Enviar" /> </form> </body> </html>
Programa java que inserta en la BD

/* Clase java */ package ln; import [Link].*; public class BD { public ResultSet rs=null; public String izena=null; public String abizena=null; public String password=null; public Connection c=null; public BD() { try{ [Link](new [Link]()); c= [Link]("jdbc:mysql://localhost:3306/personal","root",""); } catch(Exception ex){[Link](ex);} } public void insertar(){ try{ PreparedStatement ps=[Link]("insert into persona (nombre,apellidos,password) values(?,?,?)"); [Link](1, izena); [Link](2, abizena); [Link](3,password); [Link](); } catch(Exception ex){[Link](ex);} } }

You might also like