Okay, this is kinda infuriating. . . I can connect to the oracle database on a server in another city but I can’t connect to the oracle database on my own computer? What am I missing? Below is my code. . . I have even tried with both ports 1521 (and 8080 for my Tomcat server).
try
{
Connection conn;
// Load the JDBC driver
String driverName = "oracle.jdbc.driver.OracleDriver";
Class.forName(driverName);
// Create a connection to the database
String url = "jdbc:oracle:thin:@localhost";
conn = DriverManager.getConnection(url,"root","password");
}
catch (IOException e)
{
System.out.println("Caught I/O Exception);
e.printStackTrace();
throw e;
}
catch (SQLException e)
{
System.out.println("Caught SQL Exception);
e.printStackTrace();
throw e;
}
}
The URL you have is incorrect. Try this:
You have to use the right username and password and substitute the values for host and database that apply to your case. Don’t just use that string verbatim.
Is Oracle running? Can you connect using SQL*Plus? If SQL*Plus can’t connect, Java won’t be able to, either.
And the JDBC driver JAR that matches your JDK and database versions needs to be in the CLASSPATH. You should be able to find the driver JAR in the distro you downloaded.
Don’t set it using any CLASSPATH environment variables; use the
java -cpcommand line argument.Modify this code to try it out. I know that it works.