Home > front end >  Through javaweb login into abnormal data to the database
Through javaweb login into abnormal data to the database

Time:09-22

Agghh I already crazy just learning Java code played n make up can't calling bosses genuflect is begged help me solve the
The login procedure index. The JSP
<% @ page contentType="text/HTML" pageEncoding="GBK" % & gt;
<% @ page import="Java. Util. *" % & gt;

www.zhbit.com
<body>
Username: & lt; Input type="text" name="name" value="https://bbs.csdn.net/topics/
<%=reg. GetError (" errorname ") % & gt;

Age: & lt; Input type="text" name="age" value="https://bbs.csdn.net/topics/
<%=reg. GetError (" errorage ") % & gt;

Email: & lt; Input type="text" name="email" value="https://bbs.csdn.net/topics/
<%=reg. GetError (" erroremail ") % & gt;





Check the program check. JSP
<% @ page contentType="text/HTML" pageEncoding="GBK" % & gt;

<body>
<%
{if (reg. Invalidate ())
Regi. Register (reg); % & gt;
<% %} else {& gt;
<%}

% & gt;



Input your information whether legal code
Register. Java
Package zhbit;

import java.util.*;
import java.util.List;

Public class Register {
The public Register () {
super();
This. Name="";
Enclosing the age="";
This. Email="";
Errors=new HashMap (a);
}
Public String getName () {
return name;
}
Public void elegantly-named setName (String name) {
this.name=name;
}
Public String getAge () {
return age;
}
Public void setAge (String age) {
this.age=age;
}
Public String getEmail () {
Return email;
}
Public void setEmail (String email) {
This. Email=email;
}
private String name;
private String age;
private String email;
Private HashMap The errors;

Public Boolean invalidate () {
boolean flag=true;
if(! This. The name matches (" \ \ w {6, 15} ")) {
flag=false;
This. Name="";
Errors. The put (" errorname ", "user name only 6 ~ 15 Numbers or letters");
}
if(! This. Age. Matches (" \ \ d + ")) {
flag=false;
Enclosing the age="";
Errors. The put (" errorage ", "age is number");
}
if(! This. Email. Matches (" \ \ w + @ \ \ w + \ \. \ \ w + \ \.? \ \ w * ")) {
flag=false;
This. Email="";
Errors. The put (" erroremail ", "enter a legitimate email");
}
return flag;
}

Public String getError (String key) {
The String value=https://bbs.csdn.net/topics/errors.get (key);
return value !=null? Errors. The get (key) : "";
}

}
Insert the data code: RegisterDB. Java
Package the dao;

import java.sql.*;

The import DBC. DatabaseConnection;
The import zhbit. Register;

Public class RegisterDB {
Connection conn=null;
DatabaseConnection DBC=null;
Public RegisterDB () {
super();
//TODO Auto - generated constructor stub
DBC=new DatabaseConnection ();
Conn=DBC. GetConnection ();

}
Public Boolean register register (reg) throws the Exception {
A Boolean flag=false;
String SQL="INSTER INTO user (name, age, email)"
+ "VALUES (?,?,?,?,? ,? ,?) ";
PreparedStatement PSTM=conn. PrepareStatement (SQL);
PSTM. SetString (1, reg. GetName ());
PSTM. SetString (2, reg. GetAge ());
PSTM. SetString (3, reg. GetEmail ());
PSTM. ExecuteUpdate ();
PSTM. Close ();
return flag;
}
}

Error:

Myeclipse error:









CodePudding user response:

Register. The register (reg) reg function is in it? Should be reg the field inside

CodePudding user response:

PreparedStatement. Tostring () and see what it's like, directly in the database, perform and see where is an error,

CodePudding user response:

Check your insert SQL statement error is to prompt your grammar have a problem
  • Related