$ORACLE_HOME\network\admin\tnsnames.ora例如:【windows】C:\oracle\product\10.2.0\db_1\network\admin\tnsnames.oralinux或unix/oracle/product/10.2.0/db_1/network/admin/tnsnames.ora
配置文件
driver=oracle.jdbc.driver.OracleDriver#url=jdbc:oracle:thin:@127.0.0.1:1521:orcldb_ip=127.0.0.1db_name=orclusername=namepassword=pwd
getConnection文件
/***1.初始化常量*driverName驱动名称*url连接的数据库的路径*username数据库用户账户*password数据库用户密码*/static{InputStreaminput=JdbcUtils.class.getClassLoader().getResourceAsStream("MediateDB.properties");Propertiesproperties=newProperties();try{properties.load(input);driverName=properties.getProperty("driver");username=properties.getProperty("username");password=properties.getProperty("password");url="jdbc:oracle:thin:@"+properties.getProperty("db_ip")+":1521:"+properties.getProperty("db_name");dataSource=newBasicDataSource();dataSource.setDriverClassName(driverName);dataSource.setUrl(url);dataSource.setUsername(username);dataSource.setPassword(password);}catch(IOExceptione){e.printStackTrace();}}/***2.连接数据库的方法*@return*@throwsSQLException*/publicstaticConnectiongetConnection()throwsSQLException{if(conn==null)conn=dataSource.getConnection();returnconn;}
ip(127.0.0.1)端口(1521)找负责人要,没有怎么开发。端口默认是1521,IP你要一下TNSNAME也是在oracle的配置文件里配置了IP和端口,name为TNSNAME。主要用于PLSQL工具链接数据库方便。
jdbc字符串类似这样jdbc:oracle:thin:@127.0.0.1:1521:orcl并不需要tns配置
尽量用域名方式比较好,如果更换ip地址也容易。
并不需要tns配置jdbc字符串类似这样jdbc:oracle:thin:@127.0.0.1:1521:orcl