0% found this document useful (0 votes)
61 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)
61 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
You are on page 1/ 2

Configurar el entorno 1. Instalar java (jdk-6u19-windows-i586.exe) 2. Instalar Netbeans (netbeans-6.9.1-ml-java-windows.exe) 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 (index.jsp).

<%@page contentType="text/html" pageEncoding="UTF-8" import="ln.BD"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <% if (request.getParameter("izena")!=null){ BD ob=new BD();

ob.izena=request.getParameter("izena"); ob.abizena=request.getParameter("abizena"); ob.password=request.getParameter("password"); ob.insertar(); } %> <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 java.sql.*; 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{ DriverManager.registerDriver(new com.mysql.jdbc.Driver()); c= DriverManager.getConnection("jdbc:mysql://localhost:3306/personal","root",""); } catch(Exception ex){System.out.println(ex);} } public void insertar(){ try{ PreparedStatement ps=c.prepareStatement("insert into persona (nombre,apellidos,password) values(?,?,?)"); ps.setString(1, izena); ps.setString(2, abizena); ps.setString(3,password); ps.executeUpdate(); } catch(Exception ex){System.out.println(ex);} } }

You might also like