Bases de Datos - Problema con base de datos acces html .jsp apache

 
Vista:

Problema con base de datos acces html .jsp apache

Publicado por Andres (1 intervención) el 31/05/2012 00:04:30
Hola, estoy haciendo una tarea con bases de datos.
Tengo dos formularios, uno de inicio de sesion. Ese se tiene que conectar a mi base de datos en acces tiene que validar la existencia del usuario y contraseña que ingrese éste, mediante el formulario de Inicio de sesión. Para ello se debera validar primeramente que el usuario exista en la base. Si no existe, de debe notificar al usuario y muestra nuevamente la pantalla de inicio de sesión. En caso de que sí exista, valida que la contraseña que haya ingresado sea la correcta; en caso contrario, habrá que notificar al usuario y volver a mostrar la pantalla de inicio de sesión.

Luego tengo un formulario de registro, en el se registran los datos y estos simplemente se tienen que agregar a la base de datos.

El problema que tengo que no logro hacer la conexion con la base de datos pero no encuentro el porque. Les dejo los codigos que estoy manejando:
El del formulario de inicio de sesion:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<html>
<head>
<title>Iniciar Sesión</title>
</head>
<body bgcolor=#0B3861>
<center>
 
<table border="1"summary="Inicio sesión" border color=blue width=35% height=80% bgcolor=#F5ECCE>
	<tr>
		<td align=center valign=center height=35% bgcolor=#CEF6EC>
 
			<table border="0" summary="tabla" width=100% height=100%>
				<tr>
					<td align=left valign=center width=90>
						<img src="img/ipnlogo.jpg" height=130 width=90 >
					</td>
					<td align=center>
						<font face=arialblack size=5 color=#FF8000><b>Inicio de sesión</b></font><p><p>
					</td>
				</tr>
 
				<tr>
					<td align=center colspan="2">
						<font face=arialblack>
						<b>Por favor ingrese su nombre de usuario y contraseña:</b><p>
						</font>
					</td>
				</tr>
			</table>
 
		</td>
	</tr>
 
	<tr>
		<td align=center valign=center height=60%>
		<form action="iniciada.jsp" method="post">
		Usuario:<input type="text" name="usuario">
		<font face=arialblack color=#FF8000><b>*</b></font>
		<br><br><br>
		Contraseña:<input type="password" name="contra">
		<font face=arialblack color=#FF8000><b>*</b></font>
		<br><br><br>
		<input type="submit" value="Iniciar sesion">
		<input type="reset" value="Borrar todo">
		</form>
 
		<p><p><font face=arialblack color=#FF8000>
		<b>Si es usuario nuevo <a href="registro.html">dar click aquí<a> para registrarse.</b><p><p>
		</font>
 
		</td>
	</tr>
 
	<tr>
		<td align=center>
		<a href="index.html">Regresar a la pagina</a>
		</td>
	</tr>
 
</table>
 
</center>
</body>
</html>


Y su archivo .jsp con el que se debe de conectar a la base y realizar el proceso:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
 
<html><body>
 
<%!
PrintWriter out = null;
String usuario;
String password;
String strErr = "";
boolean valido = false;
%>
 
<%
usuario=request.getParameter("usuario");
password=request.getParameter("contra");
 
%>
 
<%
String connectionURL = "jdbc:mysql://localhost:8080/TiendaV";
 
Connection connection = null;
 
java.sql.Statement statement = null;
 
ResultSet rs=null;
 
 
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
 
 
 
 
connection = DriverManager.getConnection(connectionURL,"root","");
 
%>
 
<%
statement = connection.createStatement();
 
 
 
 
rs = statement.executeQuery("SELECT * FROM MUsuario ");
 
 
 
if (rs.next())
    rs = statement.executeQuery("select * from MUsuario where log_usu like '" + usuario + "' and psw_usu like '" + password + "'");
        if (rs.next()) {
            rs = statement.executeQuery("select * from MUsuario where log_usu like '" + usuario + "' and psw_usu like '" + password + "'");
            if (rs.next()) {
                valido = true;
            } else {
                strErr = "La contraseña no coincide con el usuario " + usuario + ". Verifíquelo";
                valido = false;
            }
            } else {
                strErr = "El usuario " + usuario + " no existe. Verifíquelo.";
                valido = false;
            }
 
 
 
rs.close();
statement.close();
 
%>
 
 
 
<%
out.println("<html>");
out.println("<head>");
out.println("<title>Acceso</title>");
out.println("</head>");
out.println("<body>");
if (!valido) {
    out.println("alert(' " + strErr + "');");
    out.println("window.location='indexInSes.jsp'");
             }
out.println("</body>");
out.println("</html>");
%>
<br><br><br>
<input type="button" name="Regresar" value="Regresar" onclick="window.open('indexInSes.html','_self');">
</body></html>


Luego este es mi formulario de registro:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<html>
<head>
<title>Registro</title>
</head>
<body bgcolor=#0B3861>
 
<script type="text/javascript" src="scripts/alta.js">
</script>
 
<center>
 
<table border="1"summary="altaclientes" border color=blue width=40% height=90% bgcolor=#F5ECCE>
	<tr>
		<td align=center valign=center height=15% bgcolor=#CEF6EC>
 
			<table border="0" summary="tabla" width=100% height=100%>
				<tr>
					<td align=left valign=center width=10% height=18%>
						<img src="img/ipnlogo.jpg" width=100% height=100% >
					</td>
					<td align=left>
						<font face=arialblack size=5 color=#FF8000><b>Alta de clientes</b></font><p><p>
					</td>
				</tr>
 
				<tr>
					<td align=center colspan="2" height=10>
						<font face=arialblack>
						<b>Por favor ingrese los datos del cliente a dar de alta:</b><p>
						</font>
					</td>
				</tr>
			</table>
 
		</td>
	</tr>
 
	<tr>
		<td align=center valign=center height=80%>
 
		<div>
			<FORM action="datosregistro.jsp" method="post" >
			<table BORDER="0" CELLSPACING="0" CELLPADDING="4" WIDTH="40%">
				<tr>
					<td width="30%">
					<div align="right">
					<b>ID Cliente:</b>
					</div>
					</td>
 
					<td width="70%">
					<input type="text" name="idcliente" size="40" id="id_cliente">
					</td>
				</tr>
 
				<tr>
					<td>
					<div align="right">
					<B>Nombre:</B>
					</div>
					</td>
 
					<td>
					<input type="text" name="nombre" size="40" id="nombre">
					</td>
				</tr>
 
				<tr>
					<td>
					<div align="right">
					<B>Dirección:</B>
					</div>
					</td>
 
					<td>
					<input type="text" name="direccion" size="40" id="direccion">
					</td>
				</tr>
 
				<tr>
					<td width="30%">
					<div align="right">
					<b>Ciudad:</b>
					</div>
					</td>
 
					<td width="70%">
					<input type="text" name="ciudad" size="40">
					</td>
				</tr>
 
				<tr>
					<td>
					<div align="right">
					<B>Estado:</B>
					</div>
					</td>
 
					<td>
					<input type="text" name="estado" size="40" id="estado">
					</td>
				</tr>
 
				<tr>
					<td width="30%">
					<div align="right">
					<b>Codigo Postal:</b>
					</div>
					</td>
 
					<td width="70%">
					<input type="text" name="codigopostal" size="40" id="codigo_postal">
					</td>
				</tr>
 
				<tr>
					<td>
					<div align="right">
					<B>Teléfono:</B>
					</div>
					</td>
 
					<td>
					<input type="text" name="telefono" size="40" id="telefono" onKeypress="return soloNumeros(event, false);">
					</td>
				</tr>
 
				<tr>
					<td width="30%">
					<div align="right">
					<b>Limite de credito:</b>
					</div>
					</td>
 
					<td width="70%">
					<input type="text" name="limitecredito" size="40" id="limite_credito"  onKeypress="return soloNumeros(event, true);">
					</td>
				</tr>
 
				<tr>
					<td>
					<div align="right">
					<B>Comentarios:</B>
					</div>
					</td>
 
					<td>
					<input type="text" name="comentarios" size="40" id="comentarios">
					</td>
				</tr>
 
				<tr>
					<td>&nbsp;</td>
					<td align=right><br>
					<input type="submit" name="Enviar" value="Dar de alta" onClick="return validar()">
					<input type="reset" name="Borrar" value="Cancelar">
					<br><a href="indexInSes.html">Regresar a la pagina</a>
					</td>
				</tr>
			</table>
			</form>
		</div>
 
		</td>
	</tr>
 
</table>
</center>
</body>
</html>


Y su archivo .jsp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
 
 
<html><body>
 
<%!
String idcliente;
String nombre;
String direccion;
String ciudad;
String estado;
String codigopostal;
String telefono;
String limitecredito;
String comentarios;
%>
 
<%
idcliente=request.getParameter("idcliente");
nombre=request.getParameter("nombre");
direccion=request.getParameter("direccion");
ciudad=request.getParameter("ciudad");
estado=request.getParameter("estado");
codigopostal=request.getParameter("codigopostal");
telefono=request.getParameter("telefono");
limitecredito=request.getParameter("limitecredito");
comentarios=request.getParameter("comentarios");
%>
 
<%
String connectionURL = "jdbc:mysql://localhost:8080/TiendaV";
Connection connection = null;
java.sql.Statement statement = null;
ResultSet rs=null;
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
connection = DriverManager.getConnection(connectionURL,"root","");
%>
 
<%
 
statement = connection.createStatement();
 
 
 
 
statement.executeUpdate("INSERT INTO MCliente(id_cli,nom_cli,dir_cli,cp_cli)" + "VALUES" + "('"+idcliente+"','"+nombre+"','"+direccion+"','"+codigopostal+"')");
 
 
 
statement.close();
 
connection.close();
 
 
%>
 
 
<%
out.println("<html>");
out.println("<head>");
out.println("<title>Datos de registro</title>");
out.println("</head>");
out.println("<body>");
out.println("<b><font size=+2>Datos de registro ");
out.println("<p><font size=+1><b>ID cliente: </b>"+idcliente+"</font>");
out.println("<br><font size=+1><b>Nombre: </b>"+nombre+"</font>");
out.println("<br><font size=+1> <b>Dirección: </b><i>" + direccion + "</i></font>");
out.println("<br><font size=+1><b>Ciudad: </b>" + ciudad +"</font>");
out.println("<br><font size=+1><b>Estado: </b>" + estado +"</font>");
out.println("<br><font size=+1><b>Codigo postal: </b>" + codigopostal +"</font>");
out.println("<br><font size=+1><b>Teléfono: </b>" + telefono +"</font>");
out.println("<br><font size=+1><b>Limite de crédito: </b>" + limitecredito +"</font>");
out.println("<br><font size=+1><b>Comentarios: </b>" + comentarios +"</font>");
out.println("</body>");
out.println("</html>");
%>
<br><br><br>
<input type="button" name="Regresar" value="Regresar" onclick="window.open('registro.html','_self');">
</body></html>


Espero alguien pueda ayudarme a saber que esta mal o en que falla. Como les comentaba la base de datos es un .mdb

Saludos
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder