📄 registerbean.java
字号:
package register;
import java.sql.*;
import java.util.*;
public class RegisterBean {
private Connection getConnection(){
Connection con=null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(ClassNotFoundException ce){
System.out.println("ClassNotFoundException:"+ce.getMessage());
}
try{
con=DriverManager.getConnection("jdbc:odbc:gamezone");
}catch(SQLException e){
System.out.println("RegisterBean SQLException:"+e.getMessage());
}
return con;
}
public boolean updateUser(String sql){
Connection con=null;
Statement stmt=null;
try{
con=getConnection();
stmt=con.createStatement();
stmt.executeUpdate(sql);
stmt.close();
stmt=null;
}catch(SQLException e){
System.out.println("SQLException="+e.getMessage());
}finally{
if(con!=null){
try{
con.close();
}catch(SQLException e){
System.out.println("SQLException:"+e.getMessage());
}
}
}
return true;
}
public int getUserId(){
Connection con=null;
ResultSet rs=null;
Statement stmt=null;
int userid=0;
try{
con=getConnection();
stmt=con.createStatement();
rs=stmt.executeQuery("select userId from userInfo");
while(rs.next()){
userid=rs.getInt("userId");
}
rs.close();
rs=null;
stmt.close();
stmt=null;
}catch(SQLException e){
System.out.println("SQLException="+e.getMessage());
}finally{
if(con!=null){
try{
con.close();
}catch(SQLException e){
System.out.println("SQLException:"+e.getMessage());
}
}
}
return userid;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -