-2

please how fix this error thanks a lot error: package oracle.jdbc.driver does not exist.

tell me how the package install on my PC

for my following code :

     import java.sql.*;
     import java.sql.Statement;


    public class ConnectOracle {

    public static void main(String[] args) {

    try {
        DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
        System.out.println("Connecting to the database...");
        Connection connection = DriverManager.getConnection(
                "jdbc:oracle:thin:@localhost:1521:orcl", "system", "123");
        Statement statement = connection.createStatement();
        ResultSet resultset = statement.executeQuery("select 'Connected'                                               from dual");
        resultset.next();
        String s = resultset.getString(1);
        System.out.println(s);
        statement.close();
        connection.close();
    } catch (Exception e) {
        System.out.println("The exception raised is:" + e);
    }
      }

          }

please give me some code to insert and delete (how execute ?!).Thanks .

4

2 回答 2

0

你的代码是:

DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

重写上面的代码如下,它应该可以工作

Class.forName("oracle.jdbc.driver.OracleDriver");
于 2014-03-08T09:44:21.540 回答
0

要运行非查询,您需要使用执行

statement.execute("UPDATE ...")
statement.execute("INSERT ...")
statement.execute("DELETE ...")

您可以在此处查看该方法的签名:java.sql.Statement.execute

于 2013-03-16T09:33:20.010 回答