Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class Main {
    public static void main(String args[]) throws Exception {
        Connection con = null;
        Class.forName("oracle.jdbc.driver.OracleDriver");
        con = DriverManager.getConnection("jdbc:oracle:thin:@192.201.32.92:1521:psprd1", "username", "password");
        String query = null;
        ResultSet rset = null;
        query = "UPDATE t1 " + " SET id = ?";
        PreparedStatement stmt = con.prepareStatement(query);
        // stmt.setInt(paramIndex++, null);
        stmt.setNull(1, java.sql.Types.INTEGER);
        stmt.executeUpdate();
        stmt.close();
        query = "select id from t1 ";
        stmt = con.prepareStatement(query);
        rset = stmt.executeQuery();
        rset.next();
        System.out.println(rset.getString("id"));
        rset.close();
        stmt.close();
        con.close();
    }
}