bean内容package fee;
import java.sql.*;
public class cnn{
String sDBDriver="sun.jdbc.odbc.JdbcOdbcDriver";
String sConnstr="jdbc:odbc:fee_ODBC";
String sUser="fee";
String sPassword="feefeefee";
Connection con=null;
ResultSet rs=null;
public cnn(){
try{
Class.forName(sDBDriver);
con=DriverManager.getConnection(sConnstr,sUser,sPassword);
prt("connection successful!");
}
catch(java.lang.ClassNotFoundException e){
prt(e.getMessage());
}
catch(SQLException ex){
prt(ex.getMessage());
}
}
public void prt(String str){
System.out.println(str);
}
public ResultSet dbQuery(String sql){
rs=null;
try{
Statement stmt=con.createStatement();
rs=stmt.executeQuery(sql);
prt("SQL语句:"+sql);
}
catch(SQLException ex){
prt("错误:"+ex);
}
return rs;
}
//-------------------------------------------------
public int dbUpdate(String sql){
int rows=-1;
try{
Statement stmt=con.createStatement();
rows=stmt.executeUpdate(sql);
prt("SQL:"+sql);
return rows;
}
catch(SQLException e){
prt("Update Datas error:"+e.getMessage());
return -1;
}
}
//------------------------------------------------
public boolean closeDB(){
Statement stmt=null;
try{
if(stmt!=null){
stmt.close();
stmt=null;
}
if(!con.isClosed()){
con.close();
}
return true;
}
catch(Exception e){
prt("Close DataBase error:"+e.getMessage());
return false;
}
}
//--------------------------------------------------------
//检查数据是否存在
public boolean run_chk(String str){
Statement stmt=null;
ResultSet rs=null;
try{
stmt=con.createStatement();
rs=stmt.executeQuery(str);
if(rs.next()){
prt("Search some datas");
}
else{
prt("Search no data");
}
return true;
}
catch(SQLException ex){
prt("Query data error:"+ex.getMessage());
return false;
}
}
//----------------------------------------------------------------
public int count_Select(String str){
Statement stmt=null;
ResultSet rs=null;
int rows=0;
try{
stmt=con.createStatement();
rs=stmt.executeQuery(str);
while(rs.next()){
rows++;
}
return rows;
}
catch(SQLException ex){
prt("Query data error:"+ex.getMessage());
return -1;
}
}
}
import java.sql.*;
public class cnn{
String sDBDriver="sun.jdbc.odbc.JdbcOdbcDriver";
String sConnstr="jdbc:odbc:fee_ODBC";
String sUser="fee";
String sPassword="feefeefee";
Connection con=null;
ResultSet rs=null;
public cnn(){
try{
Class.forName(sDBDriver);
con=DriverManager.getConnection(sConnstr,sUser,sPassword);
prt("connection successful!");
}
catch(java.lang.ClassNotFoundException e){
prt(e.getMessage());
}
catch(SQLException ex){
prt(ex.getMessage());
}
}
public void prt(String str){
System.out.println(str);
}
public ResultSet dbQuery(String sql){
rs=null;
try{
Statement stmt=con.createStatement();
rs=stmt.executeQuery(sql);
prt("SQL语句:"+sql);
}
catch(SQLException ex){
prt("错误:"+ex);
}
return rs;
}
//-------------------------------------------------
public int dbUpdate(String sql){
int rows=-1;
try{
Statement stmt=con.createStatement();
rows=stmt.executeUpdate(sql);
prt("SQL:"+sql);
return rows;
}
catch(SQLException e){
prt("Update Datas error:"+e.getMessage());
return -1;
}
}
//------------------------------------------------
public boolean closeDB(){
Statement stmt=null;
try{
if(stmt!=null){
stmt.close();
stmt=null;
}
if(!con.isClosed()){
con.close();
}
return true;
}
catch(Exception e){
prt("Close DataBase error:"+e.getMessage());
return false;
}
}
//--------------------------------------------------------
//检查数据是否存在
public boolean run_chk(String str){
Statement stmt=null;
ResultSet rs=null;
try{
stmt=con.createStatement();
rs=stmt.executeQuery(str);
if(rs.next()){
prt("Search some datas");
}
else{
prt("Search no data");
}
return true;
}
catch(SQLException ex){
prt("Query data error:"+ex.getMessage());
return false;
}
}
//----------------------------------------------------------------
public int count_Select(String str){
Statement stmt=null;
ResultSet rs=null;
int rows=0;
try{
stmt=con.createStatement();
rs=stmt.executeQuery(str);
while(rs.next()){
rows++;
}
return rows;
}
catch(SQLException ex){
prt("Query data error:"+ex.getMessage());
return -1;
}
}
}
if(!rst1.next()){
out.println("原用户名与密码不匹配");
}
else{
db1.dbUpdate(StrSQL);
}
rst1.close();改成db1.dbUpdate(StrSQL);
不报错,且可在数据库中插入新的数据,什么问题??