Link to home
Start Free TrialLog in
Avatar of Vignesh Vignesh
Vignesh Vignesh

asked on

java jdbc

import java.sql.*;

class JdbcInsert1
 {
   
 
   public static void main (String[] args)
 {
     
   try
 {
       
    Class.forName("oracle.jdbc.driver.OracleDriver");
     String url = "jdbc:oracle:thin:@elcot-pc:1521:system";
     
       Connection conn = DriverManager.getConnection(url,"system","tiger");
 
          Statement st = conn.createStatement();
   
         st.executeUpdate("INSERT INTO customer " +
 "VALUES (1001, 'Simpson','mtp')");
 
          st.executeUpdate("INSERT INTO customer " +
"VALUES (1002, 'McBeal','mtp')");

            st.executeUpdate("INSERT INTO customer " +
"VALUES (1003, 'Flinstone','mtp')");
     
      st.executeUpdate("INSERT INTO customer " +
"VALUES (1004, 'Cramden', 'mtp')");

 
          conn.close();
 
       }
 catch (Exception e)
{
         
   System.err.println("Got an exception! ");
 
          System.err.println(e.getMessage());

        }

    }


}

JdbcInsert.java:15: error: unreported exception ClassNotFoundException; must be
caught or declared to be thrown
            Class.forName("oracle.jdbc.driver.OracleDriver");
                         ^
1 error
plz anyone tell me solution for this problem
Avatar of krakatoa
krakatoa
Flag of United Kingdom of Great Britain and Northern Ireland image

The .jar is eiher not in the right folder, or the classpath hasn't been set properly.
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Vignesh Vignesh
Vignesh Vignesh

ASKER

i am setting classpath like below
D:\oracle\product\10.2.0\db_1\jdbc\lib\ojdbc14.jar;.

this is my error
JdbcInsert.java:15: error: unreported exception ClassNotFoundException; must be
caught or declared to be thrown
            Class.forName("oracle.jdbc.driver.OracleDriver");
                         ^
1 error
can anyone give the solution plz...
jdbcinsert.java
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
import java.sql.*;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSet;

public class jdbcinsert
{

    public static void main(String args[])
       {
        try
          {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            Connection connection= DriverManager.getConnection(
                    "jdbc:oracle:thin:@elcot-pc:1521:system", "system", "tiger");
          Statement st=connection.createStatement();
           st.executeUpdate("INSERT INTO customertab"+"VALUES(1001,'ram')");
           connection.close();
        }
         catch (ClassNotFoundException e)
           {
            e.printStackTrace();
           }
    }
}
this is my correct code  to run but it has following error
D:\vignesh>javac jdbcinsert.java
jdbcinsert.java:16: error: unreported exception SQLException; must be caught or
declared to be thrown
            Connection connection= DriverManager.getConnection(
                                                              ^
jdbcinsert.java:18: error: unreported exception SQLException; must be caught or
declared to be thrown
          Statement st=connection.createStatement();
                                                 ^
jdbcinsert.java:19: error: unreported exception SQLException; must be caught or
declared to be thrown
           st.executeUpdate("INSERT INTO customertab"+"VALUES(1001,'ram')");
                           ^
jdbcinsert.java:20: error: unreported exception SQLException; must be caught or
declared to be thrown
           connection.close();
                           ^
4 errors
can you give solution to me sir?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Closed.