Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 853955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:50:38+00:00 2026-05-15T07:50:38+00:00

I have the following Java stored procedure: CREATE OR REPLACE AND RESOLVE JAVA SOURCE

  • 0

I have the following Java stored procedure:

CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED "RetreiveLdap" AS
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Hashtable;

import javax.naming.Context;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;

public class RetreiveLdap {
    // LDAP CONFIG
    public static String CONTEXT = "com.sun.jndi.ldap.LdapCtxFactory";
    public static String HOST = "ldap://192.168.30.12:389";
    public static String USER = "cn=root,dc=company";
    public static String PASSWORD = "pa55w0rd";
    public static String BASE = "dc=company";

    // Reads from LDAP
    public static void readConfig() throws NamingException, SQLException {
        try {
            addUser("tmp", "tmp");
            Hashtable env = new Hashtable();
            env.put(Context.INITIAL_CONTEXT_FACTORY, CONTEXT);
            env.put(Context.PROVIDER_URL, HOST);
            env.put(Context.SECURITY_PRINCIPAL, USER);
            env.put(Context.SECURITY_CREDENTIALS, PASSWORD);

            DirContext ctx = new InitialDirContext(env);

            SearchControls sc = new SearchControls();
            sc.setSearchScope(SearchControls.SUBTREE_SCOPE);
            String filter = "(objectClass=person)";
            NamingEnumeration items = ctx.search(BASE, filter, sc);
            System.out.println("STARTING...");
            while (items != null && items.hasMore()) {
                SearchResult sr = (SearchResult) items.next();

                String cn = (String) sr.getAttributes().get("cn").get();
                String sn = (String) sr.getAttributes().get("sn").get();
                System.out.println("WORKING...");
                // save to table
                addUser(cn, sn);

            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // Add LDAP user to DB.
    public static void addUser(String cn, String sn) {

        try {
            Connection conn = DriverManager
                    .getConnection("jdbc:default:connection:");

            String sql = "INSERT INTO ldapuser " + "(cn,sn) " + "VALUES(?,?)";
            PreparedStatement pstmt = conn.prepareStatement(sql);
            pstmt.setString(1, cn);
            pstmt.setString(2, sn);
            pstmt.executeUpdate();
            pstmt.close();
        } catch (SQLException e) {
            System.err.println("ERROR: " + e.getMessage());
        }
    }
}
/

And I create a procedure that will run the above like;

CREATE OR REPLACE PROCEDURE read_ldap
  AS LANGUAGE JAVA
  NAME 'RetreiveLdap.readConfig()';
/

Now, when I run this class normally from java it works fine, it retrieves the list of LDAP user and saves them into the DB, (of course without the create or replace…)

But when I run it as a procedure in Oracle the users form LDAP do not get added to the table. I have added the addUser("tmp", "tmp"); just to see if my codes executes well, and with this line a user does get inserted, but none in the while loop

Is there a way to see some errors, when I run this procedure?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T07:50:38+00:00Added an answer on May 15, 2026 at 7:50 am

    I have added in SQLPLUS the following

    SQL> SET SERVEROUTPUT ON
    SQL> CALL dbms_java.set_output(2000);
    

    And I am able now to see the errors, it was related to the permission of my db user to access sockets.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 491k
  • Answers 491k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer all environment variables of that user are set Usually because… May 16, 2026 at 10:06 am
  • Editorial Team
    Editorial Team added an answer You are joining tables 4 times by the same field… May 16, 2026 at 10:06 am
  • Editorial Team
    Editorial Team added an answer This might be of some use to you. May 16, 2026 at 10:06 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have the following situation: I have a java code launching a stored procedure.
I have a stored proc in SQL Server 2005, which looks like the following
I have the following iBatis mapping for an Oracle Stored Procedure that returns a
I have the following situation... I use CallableStatement from java.sql package. When I use
So, I have the following setup in Eclipse (Java): I have a project (lets
I have the following files: view.jsp <@ page import=... <bean:define id=mForm name=myForm type=MyForm/> <html:form
I am looking for good resources on Oracle Stored Procedure geared towards beginners. I
I have a Java application that runs on Weblogic. The application needs to access
I've done some searching around but I have a specific question on SQL Injection
We build software using Hudson and Maven. We have C#, java and last, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.