2 Replies - 1081 Views - Last Post: 16 April 2009 - 08:20 PM Rate Topic: -----

#1 ಠ_ಠ  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 114
  • Joined: 26-September 08

Java and Oracle setup

Posted 16 April 2009 - 08:09 AM

I was given this example code to learn from.

CreateAlbum.java
/*
 * Created on 21-Feb-2006
 *
 * To change the template for this generated file go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */


// You need to import the java.sql package to use JDBC
import java.sql.*;
import oracle.jdbc.driver.OracleDriver;
	  
class CreateAlbum
{ 
   
 public static void main(String args[]) throws SQLException
 {
  CreateAlbum thisQ = new CreateAlbum();
  thisQ.runQuery();
 }
   
 private void runQuery()
 {
  try
  { 
   // Load the Oracle JDBC driver
   DriverManager.registerDriver(new OracleDriver());
   System.out.println("Connecting..."); 
   
   //String url = "jdbc:oracle:thin:@localhost:1521:XE";
	String url = "jdbc:oracle:oci:@global1";
   
   //Connection conn = DriverManager.getConnection(url, "SYSTEM", "****");
   Connection conn = DriverManager.getConnection(url, "****", "****");
   System.out.println("Connected.");
  
 
   try
   {
	// Create a statement
	Statement stmt = conn.createStatement();
   
	stmt.executeUpdate("DROP TABLE Album");
	System.out.println("Table dropped");
	   
	String test = "CREATE TABLE Album " + "(id NUMBER PRIMARY KEY title CHAR(40), artist CHAR(30))";
	System.out.println(test);
	   
	stmt.executeUpdate("CREATE TABLE Album " +
	 "(id NUMBER PRIMARY KEY, title CHAR(40), artist CHAR(30))" );
   
	stmt.executeUpdate("INSERT INTO Album " +
	 "VALUES (6, 'Siamese Dreams', 'Smashing Pumpkins')" );

	stmt.executeUpdate("INSERT INTO Album " +
	 "VALUES (2, 'Blood Sugar  Magik', 'Red Hot Chilli Peppers')" );
	  
	stmt.executeUpdate("INSERT INTO Album " +
	 "VALUES (3, 'Magical Mystery', 'The Beatles')" );
	
	stmt.executeUpdate("INSERT INTO Album " +
	 "VALUES (4, 'Best of the Beast', 'Iron Maiden')" );  
	
	stmt.executeUpdate("INSERT INTO Album " +
	 "VALUES (5, 'Second Coming', 'Stone Roses')" );	
	
	stmt.executeUpdate("INSERT INTO Album " +
	 "VALUES (1, 'Golden Greats', 'Ian Brown ')" ); 
	 
	ResultSet rset = stmt.executeQuery("SELECT * FROM Album " ); 
	while (rset.next()){
	 System.out.println(rset.getInt(1) +" " + rset.getString(2));  
	}
	conn.commit();
	stmt.close();
   }	 
   catch (SQLException e)
   {
	System.out.print("SQL Exception " + e);
	System.exit(1);
   }
   
  // close the result set and the statement 
   conn.close();
   System.out.println("Your JDBC installationt is correct.");
 }
  catch (SQLException e)
  {
   System.out.print("Could not connect " + e);
   System.exit(1);
  }
 }
}





Errors:


--------------------Configuration: JDK version 1.6.0_11 <Default>--------------------
C:\Documents and Settings\x00062057\Desktop\CreateModifyAlbum\CreateModifyAlbum\CreateAlbum.java:11: package oracle.jdbc.driver does not exist
import oracle.jdbc.driver.OracleDriver;
^
C:\Documents and Settings\x00062057\Desktop\CreateModifyAlbum\CreateModifyAlbum\CreateAlbum.java:27: cannot find symbol
symbol : class OracleDriver
location: class CreateAlbum
DriverManager.registerDriver(new OracleDriver());
^
2 errors

Process completed.

____________________

Im using JCreator. I was out for this but some friends said that you need to setup the compiler. But i dont know how.

Is This A Good Question/Topic? 0
  • +

Replies To: Java and Oracle setup

#2 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2209
  • View blog
  • Posts: 9,183
  • Joined: 18-February 07

Re: Java and Oracle setup

Posted 16 April 2009 - 03:43 PM

sounds like you need to put the oracle JDBC driver in your classpath.
Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8022
  • View blog
  • Posts: 31,133
  • Joined: 06-March 08

Re: Java and Oracle setup

Posted 16 April 2009 - 08:20 PM

View Postಠ_ಠ, on 16 Apr, 2009 - 07:09 AM, said:

I was given this example code to learn from.

To learn from as an example not to follow I hope :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1