Results 1 to 8 of 8
Thread: connect to oracle from java
- 07-19-2009, 07:23 AM #1
Member
- Join Date
- Jul 2009
- Posts
- 2
- Rep Power
- 0
connect to oracle from java
Hi,
I am tring to connect to oracle via java code,
I want to use a connection to oracle so i can build a database or use an already build database.
the thing is:
1- i don't know how to build a database with a table in oracle
2- i tried to get a connection with the following code:
try
{
java.sql.DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
conn = java.sql.DriverManager.getConnection("jdbc:oracle: thin:@localhost","ahmadian","pouya");
System.out.println("Connected to database!");
}
catch (java.sql.SQLException ex)
{
javax.swing.JOptionPane.showMessageDialog
(null,ex,"pouya: Failed to connect with database",javax.swing.JOptionPane.ERROR_MESSAGE);
}
but i get an error saying:
Java.sqlSQLException.listener refused the connection with the following error: ORA-12514, TNS: listener dose not currently know of service requested in connect descriptor
the connection descriptor used by the client was: local host
3- could some one answer me this: if you want to connect to oracle via NetBeans and you don't know anything about oracle what should you do, step by step with complete description neede for a 6 years old!!
I would be really thankful if any one can answer me.
Pouya.
- 07-20-2009, 03:03 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
Fairly self descriptive. It's looking for an Oracle database called localhost, which it can't find. Have you got Oracle up and running somewhere that you're trying to connect to?
No idea, I'm afraid. Oracle do reasonable walkthroughs, so they may have one.
- 07-22-2009, 06:59 AM #3
Member
- Join Date
- Jul 2009
- Posts
- 2
- Rep Power
- 0
Hi,
Thank you so much for your reply, i was completely hopeless until your hint helped me.
Now I got a new error as fallow:
java.SQLException: Io exception: The Network Adapteer could not establish the connection.
any more hints? hopefully?!
pouya.
- 07-22-2009, 09:19 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
- 07-25-2009, 05:19 PM #5
Member
- Join Date
- Jul 2009
- Posts
- 17
- Rep Power
- 0
You better try to use dsn and then try whether it is working or not
I think it will give a better solution
- 07-26-2009, 05:34 AM #6
First, are you sure you have an Oracle database running on your local system? You can get Oracle from their Web site and install it. Second, you have to create a database, tables, etc., before you can connect to it.
- 05-15-2013, 07:35 AM #7
Member
- Join Date
- May 2013
- Posts
- 2
- Rep Power
- 0
Re: connect to oracle from java
package DBM;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;
import java.lang.ClassNotFoundException;
public class OracleJDBC {
public static void main(String[] argv) {
System.out.println("-------- Oracle JDBC Connection Testing ------");
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch (ClassNotFoundException e) {
System.out.println("Where is your Oracle JDBC Driver?");
e.printStackTrace();
return;
}
System.out.println("Oracle JDBC Driver Registered!");
Connection connection = null;
try {
connection = DriverManager.getConnection("jdbc:oracle:thin:@XYZ .asiapacific.hpqcorp.net:1521:orcl", "Username","password");
} catch (SQLException e) {
System.out.println("Connection Failed! Check output console");
e.printStackTrace();
return;
}
if (connection != null) {
System.out.println("You made it, take control your database now!");
} else {
System.out.println("Failed to make connection!");
}
}
}
- 05-15-2013, 04:15 PM #8
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,606
- Rep Power
- 5
Similar Threads
-
oracle JDBC java
By silia_motor in forum JDBCReplies: 4Last Post: 05-10-2009, 09:37 AM -
why oracle index can't work correctly in oracle?
By wwwlife in forum JDBCReplies: 0Last Post: 08-27-2008, 09:27 AM -
Java + Sybase + Oracle
By xxAlemanxx in forum Advanced JavaReplies: 1Last Post: 06-26-2008, 07:41 AM -
Using JDBC to connect to ORACLE database
By Java Tip in forum Java TipReplies: 0Last Post: 02-10-2008, 11:27 AM -
Making connect 4 in java
By zoe in forum New To JavaReplies: 1Last Post: 08-07-2007, 06:10 AM


LinkBack URL
About LinkBacks


Bookmarks