与Oracle数据库OJDBCbuild立连接非常困难。
我正在使用Google Web Toolkit,并将SQL数据库添加到我的项目中。 数据库名称是议程。
我查了很多,看来这个问题对很多人来说很普遍,但是解决不了这个问题。 我已经下载“ojdbc6.jar”并添加到我的BUILDPATH中。 我刷新,closures,打开并重新打开,但我仍然看到错误。
我的规格:Windows 7 x64 Springsource – 在Eclipse数据库中也尝试过 – Oracle 10.2.0,数据库连接到我的源代码项目下的com.gwt.agenda
private static final long serialVersionUID = 1L; private Connection connection = null; private Properties props = null; private ClassLoader cl = null; private String databaseURL = ""; private String databaseUser = ""; private String databasePass = ""; public void init() { try { // Load the database connection properties from com.gwt.agenda.GWTAgendaSample.properties props = new Properties(); cl = this.getClass().getClassLoader(); InputStream is = cl.getResourceAsStream("com/gwt/agenda/GWTAgendaSample.properties"); props.load(is); // Load the database access information databaseURL = props.getProperty("databaseURL"); databaseUser = props.getProperty("databaseUser"); databasePass = props.getProperty("databasePass"); } catch (Exception e) { e.printStackTrace(); logger.error("Error loading GWTAgendaSample.properties file.", e); } try { Class.forName("oracle.jdbc.driver.OracleDriver"); // Connect to the database connection = DriverManager.getConnection(databaseURL, databaseUser, databasePass); } catch (SQLException se) { messageOut = "Unable to connect to database. Exception message: " + se.getMessage(); System.out.println(messageOut); se.printStackTrace(); // Server side log logger.error(messageOut + "\n", se); destroy(); } catch (Exception e) { messageOut = "Unable to connect to database. Exception message: " + e.getMessage(); System.out.println(messageOut); e.printStackTrace(); // Server side logger.error(messageOut + "\n", e); destroy(); } }
错误
无法连接到数据库。 exception消息:监听器拒绝与以下错误的连接:ORA-12505,TNS:侦听器当前不知道在连接描述符中给出的SID
databaseURL=jdbc:oracle:thin:@hp-PC:1521:xe databaseUser=user databasePass=agenda其中@ hp-PC是我的电脑名
有人能指出我正确的方向吗? 我错过了什么?
请帮忙!
将你的计算机名更改为hostner in listner.ora文件和tnsname.ora文件,其中安装了oracle的文件夹,比如db_1-network-admin,你将得到.ora文件,如果你的本地机是你的主机,则把你的主机改为127.0.0.1,端口1521 ..试试这个
xe你提到它应该是你的sid,检查这也