JAVA连接ORACLE数据库

当然别忘了ORACLE的数据库驱动程序
import java.sql.*;
public class DBConn
{
public static Connection getConnection()
{ //Oracle数据库连接
String ClassforName = "oracle.jdbc.driver.OracleDriver";
String SERVandDB =
"jdbc:oracle:thin:@10.6.0.120:1521:db"; //"DataSource,DataName不能用
String USER = "hr"; //用户名
String PWD = "hr"; //密码
Connection con = null;
try
{
Class.forName(ClassforName).newInstance();
con = DriverManager.getConnection(SERVandDB, USER, PWD);
con.setAutoCommit(false);
}
catch (Exception e)
{
e.printStackTrace();
}
return con;
}
}

你可能感兴趣的:(java,oracle,sql,jdbc)