amir4oracle
Programmer
The following code is giving only one error regarding the driver as stated at the end: (file name is jdbcconn.java)
The code selects empno, ename, sal from emp table and puts the data in an OS file Query1.lst
----------------------------------------------------
import java.sql.*; // 1. Import JDBC Packages
import java.io.*;
// import oracle.jdbc.driver;
// import oracle.sql;
public class jdbcconn
{
public static void main (String[] args) throws SQLException, IOException
{
// 2. Load and register the jdbc driver
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
// 3. Connecting to a Database
// Connection conn = DriverManager.getConnection("jdbcracleci8oracle.world", "scott", "tiger");
Connection conn = DriverManager.getConnection("jdbcracle:thin@laptop:1521rcl", "scott", "tiger");
// 4. Creating a Statement Object
Statement sql_stmt = conn.createStatement();
// 5. Executing the Query and Returning a ResultSet
ResultSet rset = sql_stmt.executeQuery ("Select empno, ename, sal from emp");
// 6. Process the result set,
// retrieve data in each row,
// column by column and write to an Operating System file
String str = "";
while (rset.next())
{
str += rset.getInt(1) + " " + rset.getString(2) + " " + rset.getFloat(3) + "\n";
}
byte buf[] = str.getBytes();
OutputStream fp = new FileOutputStream ("query1.lst");
fp.write (buf);
fp.close ();
// 7. Closing the ResultSet and Statement
rset.close();
sql_stmt.close();
// 8. Close the database connection
conn.close ();
}
}
--------------------------------------------------------
C:\oracle\ora81\Apache\jdk\bin>javac jdbcconn.java
jdbcconn.java:13: Class oracle.jdbc.driver.OracleDriver not found.
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver
());
1 error
---------------------------------------------------------
the compiler is showing the error "^" between driver and OracleDriver
The code selects empno, ename, sal from emp table and puts the data in an OS file Query1.lst
----------------------------------------------------
import java.sql.*; // 1. Import JDBC Packages
import java.io.*;
// import oracle.jdbc.driver;
// import oracle.sql;
public class jdbcconn
{
public static void main (String[] args) throws SQLException, IOException
{
// 2. Load and register the jdbc driver
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
// 3. Connecting to a Database
// Connection conn = DriverManager.getConnection("jdbcracleci8oracle.world", "scott", "tiger");
Connection conn = DriverManager.getConnection("jdbcracle:thin@laptop:1521rcl", "scott", "tiger");
// 4. Creating a Statement Object
Statement sql_stmt = conn.createStatement();
// 5. Executing the Query and Returning a ResultSet
ResultSet rset = sql_stmt.executeQuery ("Select empno, ename, sal from emp");
// 6. Process the result set,
// retrieve data in each row,
// column by column and write to an Operating System file
String str = "";
while (rset.next())
{
str += rset.getInt(1) + " " + rset.getString(2) + " " + rset.getFloat(3) + "\n";
}
byte buf[] = str.getBytes();
OutputStream fp = new FileOutputStream ("query1.lst");
fp.write (buf);
fp.close ();
// 7. Closing the ResultSet and Statement
rset.close();
sql_stmt.close();
// 8. Close the database connection
conn.close ();
}
}
--------------------------------------------------------
C:\oracle\ora81\Apache\jdk\bin>javac jdbcconn.java
jdbcconn.java:13: Class oracle.jdbc.driver.OracleDriver not found.
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver
());
1 error
---------------------------------------------------------
the compiler is showing the error "^" between driver and OracleDriver