JAVA JDBC: How do I establish a connection to an oracle database through JAVA?
-
I have code here that should connect me to an oracle DB through JAVA but I am getting errors, here's the Code: import java.sql.* ; import java.lang.* ; import java.io.* ; public class SimpleJdbc { public static void main(String[] args) throws SQLException, ClassNotFoundException { //load the JDBC Driver Class.forName("oracle.jdbc.driver.Oracle… System.out.println("Driver loaded"); // Establish a connection Connection connection = DriverManager.getConnection ("jdbc:oracle:thin:@edgar1.cse.lehigh.ed… System.out.println("Database connected"); // create a statement Statement statement = connection.createStatement(); // execute a statement ResultSet resultSet = statement.executeQuery ("select course_id, title, dept_name from course"); // Iterate through the result and print the information while (resultSet.next()) System.out.println(resultSet.getString(1… + "\t" + resultSet.getString(2) + "\t" + resultSet.getString(3)); // close the connection connection.close(); } } All of the Connection URL info is correct and I use an actual USERNAME and PASSWORD in trying to connect, but when I run this I get the following error: java.lang.ClassNotFoundException at edu.rice.cs.plt.reflect.PathClassLoader.… at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Unknown Source) at SimpleJdbc.main(SimpleJdbc.java:13) at sun.reflect.NativeMethodAccessorImpl.inv… Method) at sun.reflect.NativeMethodAccessorImpl.inv… Source) at sun.reflect.DelegatingMethodAccessorImpl… Source) at java.lang.reflect.Method.invoke(Unknown Source) at edu.rice.cs.drjava.model.compiler.JavacC… > Does anyone see a problem with the code, How can I make this code connect me to a database or can someone supply me with code that works to establish a DB connection, where I can type in the connection URL and my user name and password? Thanks in advance,l really need help with this
-
Answer:
Did you include the Oracle JDBC driver in your class path ?
biily b at Yahoo! Answers Visit the source
Related Q & A:
- How do I make a window in Java?Best solution by Stack Overflow
- How can I make a Spinner only by java?Best solution by stackoverflow.com
- How do I change a password directly in the PhpBB3 SQL database?Best solution by Server Fault
- How do I get a WiFi connection for my iPod Touch?Best solution by Yahoo! Answers
- How do I delete a connection request I had sent?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.