不知道为什么呀
总是不能调用那里面的方法呀
好心人帮帮我看看????????????????
先在此谢过
package database;
import java.sql.*;
import java.util.*;
import sun.io.*;
public class OPDB{
//DBConnectionMannager connMgr;
Connection conn =null;
Statement sqlStatement =null;
ResultSet results =null;
ResultSet retemp =null;
ResultSetMetaData resultsMeta =null;
boolean status;
String sql;
int columns;
long rowcount =0;
//连接数据库
public void connection(){
try{
/*DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
this.conn =DriverManager.getConnection ("jdbc:oracle:thin:@10.10.10.220:1521:market","sz_hk", "sz_hk");
*/
//connMgr = DBConnectionMannager.getInstance();
//conn =connMgr.getConnection("sz_hk");
this.status =true;
}catch(Exception e)
{
this.status =false;
}
}
//连接数据库
public void connection(String con,String username,String password){
try{
con="jdbc:odbc:zhong";
DriverManager.registerDriver(new sun.jdbc.odbc.JdbcOdbcDriver());
this.conn =DriverManager.getConnection (con,"sa","342323");
this.status =true;
}catch(SQLException e)
{
this.status =false;
}
}
// 返回连接
public Connection getConn(){
/* try{
DBConnectionMannager connMgr;
connMgr = DBConnectionMannager.getInstance();
Connection conn =connMgr.getConnection("sz_hk");
if(conn !=null)
this.status =true;
else
this.status =false;
}catch(Exception e){
System.out.println( e.toString());
}*/
return this.conn ;
}
// 关闭对数据库的连接等。
public void Close(){
try{
if(this.conn !=null)
this.conn.close();
if(this.sqlStatement !=null)
this.sqlStatement.close();
if(this.results !=null)
this.results.close();
//this.connMgr.release();
this.status =true;
}catch(SQLException e){
this.status =false;
}
}
//从数据库中选择数据
public synchronized ResultSet select(Connection c,String sql){
int index =0;
//Assign passed arguments
this.conn =c;
this.sql =sql;
try{
//Create Statement Object and Execute SQL
sqlStatement =this.conn.createStatement();
retemp =sqlStatement.executeQuery(this.sql);
this.rowcount =0;
//Get the column count for the result set
this.rowcount =0;
while(this.retemp.next())
this.rowcount++;
if(retemp!=null)
retemp.close();
results =sqlStatement.executeQuery(this.sql);
resultsMeta =results.getMetaData();
this.columns =resultsMeta.getColumnCount();
this.status =true;
return results;
}catch(SQLException e){
this.status =false;
return null;
}
}
//返回结果集的列数目
public int getColumns(){
return this.columns;
}
//返回结果集的行数目
public long getRowcount(){
return this.rowcount;
}
// 修改数据库中的记录。
public void update(Connection c,String sql){
try{
Statement sqlStatement =c.createStatement();
sqlStatement.executeUpdate(sql);
status =true;
}catch(SQLException e){
//set status to flase
status =false;
}
}
//向数据库中插入记录。
public synchronized void insert(Connection c,String sql){
try{
Statement sqlStatement =c.createStatement();
sqlStatement.executeUpdate(sql);
//set status variable to true
this.status =true;
}catch(SQLException e){
//set status variable to true
this.status =false;
}
}
// 删除记录 。
public synchronized void delete(Connection c,String sql){
try{
sqlStatement =this.conn.createStatement();
sqlStatement.executeUpdate(sql);
status =true;
}catch(SQLException e){
//set status to flase
status =false;
}
}
//删除所有记录。
public void deleteAll(String table){
String sql ="delete from "+table;
try{
sqlStatement =this.conn.createStatement();
sqlStatement.executeUpdate(sql);
status =true;
}catch(SQLException e){
status =false;
}
}
//返回对数据库的操作是否成功
public boolean getSuccess(){
return this.status;
}
//转换为中文字符
public String GBK(String action){
try{
byte[] b =action.getBytes("GB2312");
String convert =new String(b,"8859_1");
return convert;
}catch(Exception e){
}
return null;
}
public static String AsciiToChineseString(String s)
{
char[] orig =s.toCharArray();
byte[] dest =new byte[orig.length];
for(int i=0;i<orig.length;i++)
dest[i] =(byte)(orig[i]&0xFF);
try{
ByteToCharConverter toChar =ByteToCharConverter.getConverter("gb2312");
return new String(toChar.convertAll(dest));
}catch(Exception e){}
return s;
}
public String replace(String con ,String tag,String rep){
int j=0;
int i=0;
int k=0;
String RETU="";
String temp =con;
int tagc =tag.length();
while(i<con.length()){
if(con.substring(i).startsWith(tag)){
temp =con.substring(j,i)+rep;
RETU+= temp;
i+=tagc;
j=i;
}
else{
i+=1;
}
}
RETU +=con.substring(j);
return RETU;
}
}