G
gbman
Unregistered / Unconfirmed
GUEST, unregistred user!
db.java
package mypackae;
import java.io.*;
import java.lang.*;
import java.net.*;
import java.sql.*;
import java.util.*;
public class db implements Serializable
{
static Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
public db()
{
}
public static void getConnection()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn=DriverManager.getConnection("jdbcdbc:userinfo","local","windows nt");
}catch(java.lang.ClassNotFoundException e)
{
System.err.println("mydb():"+ e.getMessage());
}catch(java.sql.SQLException e)
{
System.err.println("db():"+ e.getMessage());
}
}
public void closeConnection()
{
try {
if(rs!=null)
rs.close();
if(stmt!=null)
stmt.close();
if(conn!=null)
conn.close();
}catch(java.sql.SQLException e)
{
System.err.println("db():"+ e.getMessage());
}
rs=null;
stmt=null;
conn=null;
}
public ResultSet executeQuery(String sql)
{
rs=null;
try {
if(conn==null)
getConnection();
if(conn!=null)
{
stmt=conn.createStatement();
rs=stmt.executeQuery(sql);
}
}catch(SQLException e)
{
System.err.println("db.executeQuery:"+ e.getMessage());
}
return rs;
}
public boolean executeUpdate(String sql)
{
boolean bupdate=false;
try{
if(conn==null)
getConnection();
if(conn!=null)
{
stmt=conn.createStatement();
int rowCount=stmt.executeUpdate(sql);
if(rowCount!=0)
bupdate=true;
}
}catch(SQLException ex)
{
System.err.println("db.executeUpdate:"+ ex.getMessage());
}
return bupdate;
}
public static String toChinese(String strvalue)
{
try{
if(strvalue==null)
{
return null;
}
else
{
strvalue=new String(strvalue.getBytes("ISO8859_1"),"GBK");
return strvalue;
}
}catch (Exception e)
{
return null;
}
}
}
MoneyBean.java
package mypackage;
import java.sql.*;
import java.lang.*;
public class MoneyBean extends db
{
private String username=null;
private String passwords=null;
private long moneys=0L;
boolean queryByName()
{
boolean beExit=false;
ResultSet rs=null;
if(username==null) return false;
try{
String sql="select * from userinfo where username='"+username+"'";
rs=executeQuery(sql);
if(rs.next())
{
passwords=rs.getString("passwords");
moneys=rs.getLong("moneys");
beExit=true;
}
}catch(Exception ex)
{
System.err.println("MoneyBean.queryByName:"+ex.getMessage());
}
finally{
return beExit;
}
}
boolean updatemoney(long newmoney)
{
if(username==null)return false;
try{
String sql="update userinfo set moneys="+newmoney+"where username='"+username+"'";
bupdate=executeUpdate(sql);
}catch(Exception ex)
{
System.err.println("MoneyBean.updateMoney:"+ ex.getMessage());
}
finally{
return bupdate;
}
}
boolean updatepassword(String newpasswd)
{
if(username==null)return false;
boolean bupdate=false;
try{
String sql="update userinfo setpasswords='"+newpasswd+"'where username='"+username+"'";
bupdate=executeUpdate(sql);
}catch(Exception ex)
{
System.err.println("MoneyBean.updatepaswords:"+ex.getMessage());
}
finally{
return bupdate;
}
}
public String getusername()
{
return username;
}
public boolean setusername(String newusername)
{
username=db.toChinese(newusername);
boolean success=queryByName();
return success;
}
public String getpasswords()
{
return passwords;
}
public boolean setpasswords(String newpasswords)
{
passwords=newpasswords;
boolean success=updatepasswords(newpasswords);
return success;
}
public long getMoney()
{
money=newmoney;
boolean success=updatemoney(newmoney);
return success;
}
public void release()
{
closeConnection();
}
}
/*
public static void main(String arge[])
{
MoneyBean testBean=new MoneyBean();
testBean.setusername("liu");
String passwd=testBean.getpassword();
System.out.println("the old passwords of user is"+passwd+"/r/n");
testBean.setpasswords("11235");
long tempMoney=testBean.getmoney();
System.out.println("the old moneys of user is "+tempMoney+"/r/n");
testBean.setmoney(2000L);
}*/
为什么运行MoneyBean.java总有错,,但我又不知道错在哪里。。高手指点一下呀,
package mypackae;
import java.io.*;
import java.lang.*;
import java.net.*;
import java.sql.*;
import java.util.*;
public class db implements Serializable
{
static Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
public db()
{
}
public static void getConnection()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn=DriverManager.getConnection("jdbcdbc:userinfo","local","windows nt");
}catch(java.lang.ClassNotFoundException e)
{
System.err.println("mydb():"+ e.getMessage());
}catch(java.sql.SQLException e)
{
System.err.println("db():"+ e.getMessage());
}
}
public void closeConnection()
{
try {
if(rs!=null)
rs.close();
if(stmt!=null)
stmt.close();
if(conn!=null)
conn.close();
}catch(java.sql.SQLException e)
{
System.err.println("db():"+ e.getMessage());
}
rs=null;
stmt=null;
conn=null;
}
public ResultSet executeQuery(String sql)
{
rs=null;
try {
if(conn==null)
getConnection();
if(conn!=null)
{
stmt=conn.createStatement();
rs=stmt.executeQuery(sql);
}
}catch(SQLException e)
{
System.err.println("db.executeQuery:"+ e.getMessage());
}
return rs;
}
public boolean executeUpdate(String sql)
{
boolean bupdate=false;
try{
if(conn==null)
getConnection();
if(conn!=null)
{
stmt=conn.createStatement();
int rowCount=stmt.executeUpdate(sql);
if(rowCount!=0)
bupdate=true;
}
}catch(SQLException ex)
{
System.err.println("db.executeUpdate:"+ ex.getMessage());
}
return bupdate;
}
public static String toChinese(String strvalue)
{
try{
if(strvalue==null)
{
return null;
}
else
{
strvalue=new String(strvalue.getBytes("ISO8859_1"),"GBK");
return strvalue;
}
}catch (Exception e)
{
return null;
}
}
}
MoneyBean.java
package mypackage;
import java.sql.*;
import java.lang.*;
public class MoneyBean extends db
{
private String username=null;
private String passwords=null;
private long moneys=0L;
boolean queryByName()
{
boolean beExit=false;
ResultSet rs=null;
if(username==null) return false;
try{
String sql="select * from userinfo where username='"+username+"'";
rs=executeQuery(sql);
if(rs.next())
{
passwords=rs.getString("passwords");
moneys=rs.getLong("moneys");
beExit=true;
}
}catch(Exception ex)
{
System.err.println("MoneyBean.queryByName:"+ex.getMessage());
}
finally{
return beExit;
}
}
boolean updatemoney(long newmoney)
{
if(username==null)return false;
try{
String sql="update userinfo set moneys="+newmoney+"where username='"+username+"'";
bupdate=executeUpdate(sql);
}catch(Exception ex)
{
System.err.println("MoneyBean.updateMoney:"+ ex.getMessage());
}
finally{
return bupdate;
}
}
boolean updatepassword(String newpasswd)
{
if(username==null)return false;
boolean bupdate=false;
try{
String sql="update userinfo setpasswords='"+newpasswd+"'where username='"+username+"'";
bupdate=executeUpdate(sql);
}catch(Exception ex)
{
System.err.println("MoneyBean.updatepaswords:"+ex.getMessage());
}
finally{
return bupdate;
}
}
public String getusername()
{
return username;
}
public boolean setusername(String newusername)
{
username=db.toChinese(newusername);
boolean success=queryByName();
return success;
}
public String getpasswords()
{
return passwords;
}
public boolean setpasswords(String newpasswords)
{
passwords=newpasswords;
boolean success=updatepasswords(newpasswords);
return success;
}
public long getMoney()
{
money=newmoney;
boolean success=updatemoney(newmoney);
return success;
}
public void release()
{
closeConnection();
}
}
/*
public static void main(String arge[])
{
MoneyBean testBean=new MoneyBean();
testBean.setusername("liu");
String passwd=testBean.getpassword();
System.out.println("the old passwords of user is"+passwd+"/r/n");
testBean.setpasswords("11235");
long tempMoney=testBean.getmoney();
System.out.println("the old moneys of user is "+tempMoney+"/r/n");
testBean.setmoney(2000L);
}*/
为什么运行MoneyBean.java总有错,,但我又不知道错在哪里。。高手指点一下呀,