| |

VerySource

 Forgot password?
 Register
Search
View: 635|Reply: 0

Why is no data inserted? Urgent ~!

[Copy link]

2

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-6 09:30:01
| Show all posts |Read mode
One of them: UserReg.java
package xiuxianblog.connects;
import java.sql. *;
import xiuxianblog.connects.connDB;
public class UserReg {
connDB conndb = new connDB ();
Connection con = null;
Statement stmt;
ResultSet rt;
Ransom
String username;
String blogname;
String petname;
String pwd;
String pwdclew;
String pwdkey;
String email;
String age;
String sex;
String province;
String city;
Ranch
// setter method
public void setusername (String newusername) {
username = newusername;
}
public void setblogname (String newblogname) {
blogname = newblogname;
}
public void setpetname (String newpetname) {
petname = newpetname;
}
public void setpwd (String newpwd) {
pwd = newpwd;
}
public void setpwdclew (String newpwdclew) {
pwdclew = newpwdclew;
}
public void setpwdkey (String newpwdkey) {
pwdkey = newpwdkey;
}
public void setemail (String newemail) {
email = newemail;
}
public void setage (String newage) {
age = newage;
}
public void setprovince (String newprovince) {
province = newprovince;
}
public void setsex (String newsex) {
sex = newsex;
}
public void setcity (String newcity) {
city ​​= province + newcity;
}
// getter method
public String getusername () {
return username;
}
public String getblogname () {
return blogname;
}
public String getpetname () {
return petname;
}
public String getpwd () {
return pwd;
}
public String getpwdclew () {
return pwdclew;
}
public String getpwdkey () {
return pwdkey;
}
public String getemail () {
return email;
}
public String getage () {
return age;
}
public String getsex () {
return sex;
}
public void selectDate (String Username) {
ResultSet rs;
try {
rs = stmt.executeQuery ("select * from Blog_User where UserName = '" + username + "'");
rs.next ();
username = rs.getString ("username");
blogname = rs.getString ("blogname");
petname = rs.getString ("petname");
pwdclew = rs.getString ("pwdclew");
pwdkey = rs.getString ("pwdkey");
email = rs.getString ("email");
age = rs.getString ("age");
}
catch (Exception em) {
em.printStackTrace ();
}
}
Ranch
Ransom
public String ValiDate () {// If the return value is right, the registration is successful, if it is username, it means that the account is a duplicate
String t = "null";
ResultSet rs;
try {
rs = stmt.executeQuery ("select username from Blog_User");
while (rs.next ()) {
String name = rs.getString ("username");
if (name.equals (username)) {
t = "username"; // username repeated
break;
}
else {
t = "right";
}
}
if (t.equals ("right")) {// t = right, the registration was successful
InsertDate ();
}
if (t.equals ("null")) {// t = null, that is, the database has data input for the first time
InsertDate ();
}
con.close ();
stmt.close ();
}
catch (Exception em) {
em.printStackTrace ();
}
return t;
}
public void InsertDate () {
try {

stmt.executeUpdate ("insert into Blog_User (username, Blog_Name, User_Petname, User_Pwd, User_Pwdclew, User_Pwdkey, User_Email, User_Age, User_Sex, User_City) values ​​('" + username + "', '" + blogname + "'," "+ petname ',' "+ pwd +" ',' "+ pwdclew +" ',' "+ pwdkey +" ',' "+ email +" ',' "+ age +" ',' "+ sex +" ',' "+ city +" ' ) ");
}
catch (Exception e) {
e.printStackTrace ();
Ranch
}
}
}
The second connDB.java
package xiuxianblog.connects;

import java.sql. *;

public class connDB
{
// For security reasons, the database connection, user name and password are set to private type, and other classes are forbidden to view
private static Connection con = null;
    private static String url = "jdbc: microsoft: sqlserver: //127.0.0.1: 1433; DatabaseName = Blog_DB";
private static String user = "sa";
private static String pwd = "sa";
    
    public static Connection getConnection ()
    {
        try
        {
            Class.forName ("com.microsoft.jdbc.sqlserver.SQLServerDriver"). NewInstance ();
con = DriverManager.getConnection (url, user, pwd);
        }
        catch (Exception e)
        {
            e.printStackTrace ();
        }
        return con;
    }
}
JSP file
<% @ page contentType = "text / html; charset = gb2312" import = "xiuxianblog.connects. *"%>
<jsp: useBean id = "rs" class = "xiuxianblog.connects.connDB" />
<html>
<body>
<%! String vd;%>
<%

rs.setusername (request.getParameter ("username"));
rs.setblogname (request.getParameter ("blogname"));
rs.setpetname (request.getParameter ("petname"));
rs.setpwd (request.getParameter ("pwd"));
rs.setpwdclew (request.getParameter ("pwdclew"));
rs.setpwdkey (request.getParameter ("pwdkey"));
rs.setemail (request.getParameter ("email"));
rs.setage (request.getParameter ("age"));
rs.setsex (request.getParameter ("sex"));
rs.setprovince (request.getParameter ("province"));
rs.setcity (request.getParameter ("city"));
vd = "right";

if (vd.equals ("right")) {
%>
<script language = "javascript">
<!-
alert ("Congratulations on your successful registration");
location = 'index.jsp';
->
</ script>
<%
}
if (vd.equals ("null")) {
%>
<script language = "javascript">
<!-
out.print (username);
alert ("Congratulations on your successful registration");
location = 'index.jsp';
->
</ script>
<%
}
if (vd.equals ("username")) {
%>
<script language = "javascript">
<!-
alert ("The user already exists");
location = 'register.jsp';
->
</ script>

</ body>
</ html>
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list