Results 1 to 3 of 3
- 12-17-2008, 06:22 PM #1
Member
- Join Date
- Sep 2008
- Posts
- 42
- Rep Power
- 0
errors when trying to connect to database
Hi all,
I am trying to connect to a database within a class:
when I try to run this I get the following error:Java Code:import java.sql.*; class SimpleOraJava { public static void main(String args[]) throws SQLException { DriverManager.registerDriver( new oracle.jdbc.driver.OracleDriver() ); String serverName = "nikuuat"; int port = 1521; String user = "niku"; String password = "niku"; String SID = "nikuuat"; String URL = "jdbc:oracle:thin:@" + serverName + ":" + port + ":" + SID; Connection conn = DriverManager.getConnection(URL, user, password); String SQL = "SELECT DSTI_PROJ_REF FROM NIKU.ODF_CA_PROJECT"; Statement stat = conn.createStatement(); ResultSet rs = stat.executeQuery(SQL); while (rs.next()) { System.out.println( rs.getInt(1) + "\t" + rs.getString(2) ); } stat.close(); conn.close(); } }
i'm not sure what to do, can anybody advise?Java Code:run: Exception in thread "main" java.sql.SQLException: Io exception: The Network Adapter could not establish the connection at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134) at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179) at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:334) at oracle.jdbc.ttc7.TTC7Protocol.handleIOException(TTC7Protocol.java:3695) at oracle.jdbc.ttc7.TTC7Protocol.logon(TTC7Protocol.java:352) at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:362) at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:536) at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:328) at java.sql.DriverManager.getConnection(DriverManager.java:582) at java.sql.DriverManager.getConnection(DriverManager.java:185) at SimpleOraJava.main(SimpleOraJava.java:30) Java Result: 1 BUILD SUCCESSFUL (total time: 2 seconds)
thanks in advance,
Matt
- 12-17-2008, 11:01 PM #2
Member
- Join Date
- Sep 2008
- Posts
- 42
- Rep Power
- 0
can anyone help me?
- 12-18-2008, 12:06 AM #3
Senior Member
- Join Date
- Nov 2008
- Posts
- 286
- Rep Power
- 5
Not too familiar with Oracle or this particular JDBC driver, but if I was coming at this new, I would:
- double tripple check the URL format -- I know they're different drivers and the format isn't standard, but compared to the format for connecting to MySQL or connecting to SQL Server, the format you have above looks quite odd
- does your DB log anything useful? (like a "permission denied to client XXX" message)
- can you connect from the same machine to the DB but via a different means, e.g. an interactive SQL client?
- is Java even getting as far as sending anything down the network? - if the DB is on a different box, install a packet sniffer and check that some data is actually being sent across the network and some coming back in? if something is going out but not coming back in, what does a packet sniffer on the DB machine pick up? any firewall in the way of the two that you should be aware of?Last edited by neilcoffey; 12-18-2008 at 12:07 AM. Reason: forgot sth
Neil Coffey
Javamex - Java tutorials and performance info
Similar Threads
-
how to connect to a PC database from a mobile aaplication?
By nathilen in forum Advanced JavaReplies: 0Last Post: 11-06-2008, 09:07 AM -
Help with Java application to connect to a database
By coco in forum JDBCReplies: 3Last Post: 09-18-2008, 03:07 PM -
connect JDBC to offline database
By nancyhung in forum JDBCReplies: 1Last Post: 04-11-2008, 11:04 PM -
Using JDBC to connect to ORACLE database
By Java Tip in forum Java TipReplies: 0Last Post: 02-10-2008, 11:27 AM -
Problem to connect Database
By Swamipsn in forum NetBeansReplies: 1Last Post: 08-07-2007, 07:13 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks