package jp.co.nec.JTC;import java.sql.*;
import java.util.*;
import java.io.*;
public class JTCDBConnectionF implements Serializable{
protected Connection con = null;
public JTCDBConnectionF() { }
public void dbOpen() throws java.lang.Exception{
if (con == null || con.isClosed()) {
String url = "jdbc:oracle:oci8:@apsv";
String user = "scott";
String pass = "tiger";
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
con = DriverManager.getConnection(url,user,pass);
con.setTransactionIsolation( con.TRANSACTION_READ_COMMITTED );
con.setAutoCommit(false); System.out.println("DB OPEN");
} else {
System.out.println("OPENED DB");
}
}
public JTCerrorF dbClose() {
try {
if (con != null && !con.isClosed()) {
con.rollback();
con.close();
System.out.println("DB CLOSE");
} else {
System.out.println("CLOSED DB");
}
}
catch (SQLException se) {
// return new JTCerrorF(se.getErrorCode(),se);
return new JTCerrorF("PD05",se); //DB CLOSE
}
finally {
con = null;
}
return (JTCerrorF)null;
}
}来这里看看对你有帮助
import java.util.*;
import java.io.*;
public class JTCDBConnectionF implements Serializable{
protected Connection con = null;
public JTCDBConnectionF() { }
public void dbOpen() throws java.lang.Exception{
if (con == null || con.isClosed()) {
String url = "jdbc:oracle:oci8:@apsv";
String user = "scott";
String pass = "tiger";
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
con = DriverManager.getConnection(url,user,pass);
con.setTransactionIsolation( con.TRANSACTION_READ_COMMITTED );
con.setAutoCommit(false); System.out.println("DB OPEN");
} else {
System.out.println("OPENED DB");
}
}
public JTCerrorF dbClose() {
try {
if (con != null && !con.isClosed()) {
con.rollback();
con.close();
System.out.println("DB CLOSE");
} else {
System.out.println("CLOSED DB");
}
}
catch (SQLException se) {
// return new JTCerrorF(se.getErrorCode(),se);
return new JTCerrorF("PD05",se); //DB CLOSE
}
finally {
con = null;
}
return (JTCerrorF)null;
}
}来这里看看对你有帮助
而我机器上用的是sql 7.0
兼容性很好啊!!!
Exception in thread "main" java.sql.SQLException: [Microsoft][SQLServer 2000 Dri
ver for JDBC]This version of the JDBC driver only supports Microsoft SQL Server
2000. You can either upgrade to SQL Server 2000 or possibly locate another vers
ion of the driver.
搞定了!