📄 register.java
字号:
import java.sql.*;
//普通用户注册
public class register {
public static final String INSERTUSER = "insert into user(name,password,id,question,answer,account,sum,shopname) values(?,?,?,?,?,?,?,?)";
//插入个人信息
public static boolean insertUser(String name, String password2,String id, String question,String answer,String account,double sum,String shopname)
{
boolean flag = false;
Connection conn = null;
String username="root";
String password="111111";
String url = "jdbc:mysql://localhost:3306/shoppingmall";
try{
//-------------加载驱动-------------------------
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
System.out.println("Success loading Mysql Driver!");
}
catch(Exception e){
System.out.println("Error loading Mysql Driver!");
}
try{
conn = DriverManager.getConnection(url,username,password);
// System.out.println("Success connect Mysql Database!");
}
catch(SQLException e){
System.out.println(e.getMessage());
}
PreparedStatement pstmt = null;
int count = 0;
try
{
pstmt = conn.prepareStatement(INSERTUSER);
pstmt.setString(1, name);
pstmt.setString(2, password2);
pstmt.setString(3, id);
pstmt.setString(6,account);
pstmt.setString(4, question);
pstmt.setString(5, answer);
pstmt.setDouble(7, sum);
pstmt.setString(8, shopname);
count = pstmt.executeUpdate(); // 记录操作执行的记录条数
if (count != 0)
{
flag = true;
}
}
catch (SQLException e)
{
e.printStackTrace();
}
finally
{
if (null != conn)
{
try
{
conn.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (null != pstmt)
{
try
{
pstmt.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
return flag;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -