import java.sql.*;
import java.util.ArrayList;
import DBTables.*;
public class ZxsOracle
{
private static Connection cn;
private static Statement stmt;
private static ResultSet rs;
/*
* 0:打开数据库连接成功;
* -1:打开数据库连接失败:未找到驱动程序
* -2:打开数据库连接失败:参数错
*/
public static int openConnection( String serverIP,String DBname,String user,String password )
{
int conResult = 0;
try
{
String dbNameThin = "jdbc:oracle:thin:@" + serverIP + ":1521:" + DBname;
DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
cn = DriverManager.getConnection( dbNameThin, user, password );
stmt = cn.createStatement();
}
catch (SQLException e)
{
conResult = -2;
e.printStackTrace();
}
return conResult;
}
//查询:select
public static ResultSet query( String queryStr ) throws SQLException
{
rs = stmt.executeQuery( queryStr );
return rs;
}
/*
* 用于执行 INSERT、UPDATE 或 DELETE 语句(返回受影响的行数)
* 以及 SQL DDL(数据定义语言)语句,例如: CREATE TABLE 和 DROP TABLE(总是返回0)
*/
public static int change( String changeStr ) throws SQLException
{
int resultInt = -1;
resultInt = stmt.executeUpdate( changeStr );
return resultInt;
}
/*
* 0:关闭数据库连接成功;
* -1:关闭数据库连接失败
*/
public static int closeConnection() throws SQLException
{
if(rs!=null)
{
rs.close();
}
if(stmt!=null)
{
stmt.close();
}
if(cn!=null)
{
cn.close();
}
return 0;
}
//测试代码
public static void main(String[] args) throws SQLException
{
int conResult = ZxsOracle.openConnection("localhost","oradb01","guest","guest");
System.out.println( "连接数据库状态:" + conResult );
int closeResult = ZxsOracle.closeConnection();
System.out.println( "关闭数据库连接状态:" + closeResult );
}
}
========================================
这段代码在别人的机器就好,但是到我的机器就报错(红颜色的代码),是不是我哪个的地方还需要配置啊?请教各位高手!!