Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Java tools & IDE's > Ошибка при запуске jar


Автор: Kverter 29.1.2014, 11:18
Здравствуйте! Собрал архив jar в JDeveloper вод код класса
Код

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Hashtable;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.NamingEnumeration;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.*;
import java.io.File;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Iterator;
import java.util.Properties;
import java.util.Enumeration;
import java.util.Iterator;
import java.io.UnsupportedEncodingException;
import java.util.List;
import javax.naming.NamingException;
public class Class1 
{
    private static final String sFileName = "my.properties";
    private static String sDirSeparator = System.getProperty("file.separator");
    private static Properties props = new Properties();
    private static Statement st;

    public static void main(String[] args) throws Exception 
    {
       ADGroup(ADconn());
    }
    public static String PropertyReader(String arg) throws FileNotFoundException, IOException {
           
            // определяем полный путь к файлу
            String sFilePath = "C:\\config.ini";
            // создаем поток для чтения из файла
            FileInputStream ins = new FileInputStream(sFilePath);
            // загружаем свойств
            props.load(ins);
            //System.out.println(props.getProperty(arg));
       
            return props.getProperty(arg);
        }
    public static Statement JDBCConn() throws SQLException, FileNotFoundException, IOException {
          
    String user = PropertyReader("LoginDB");//Логин пользователя
    String password = PropertyReader("PasswordDB");//Пароль пользователя
    String url = PropertyReader("URLDB");//URL адрес
    String driver = "oracle.jdbc.OracleDriver";//Имя драйвера
    try {
    Class.forName("oracle.jdbc.OracleDriver");//Регистрируем драйвер
    } catch (ClassNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    Connection c = null;//Соединение с БД
    //подготавливаем запрос с параметрами
        
        c = DriverManager.getConnection (url, user, password);
             Statement st = c.createStatement();
             System.out.println("CONNECT");
             return st;
    }      
    public static void ADGroup(DirContext arg) throws FileNotFoundException, IOException, SQLException, NamingException, Exception {
       Statement st = Class1.JDBCConn();
        DirContext GroupContext = arg;
        SearchControls GroupControls = new SearchControls();
        GroupControls.setReturningAttributes(new String[] {"name","member"});
        GroupControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
       NamingEnumeration results = GroupContext.search(PropertyReader("linesearch"),"(&(objectCategory=group)(name=0BSL*))", GroupControls);
       //////////////////////////////////////////////////////////////////////////////
       //  SearchControls usersControls = new SearchControls();
       // usersControls.setReturningAttributes(new String[] {"name"});
       // usersControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
                  // Цикл по группам (Organisation Unit'ам) 
        int k =0;
        String userPrincipalName;
                  while (results != null && results.hasMoreElements()) 
                  {
                      
                      String role = "";
                      SearchResult result = (SearchResult) results.next();
                      Attribute attribute = result.getAttributes().get("name");
                      if (attribute == null) {
                          continue;
                      }
                      String groupName = (String) attribute.get();
                       //String groupDN = (String) result.getAttributes().get( "distinguishedName").get();
                        String memberOF = "";

           System.out.println("Group = "+groupName);
           
                      if (result.getAttributes().get("member")!=null)
                      {
                   NamingEnumeration member = result.getAttributes().get( "member").getAll();
                   int v=member.hashCode();
                   while((member!=null)&&(member.hasMoreElements()))
                   {
                          //System.out.println("HROUPNAME = "+groupName+ " memberOF = "+member.next());
                          Connection C= JDBCConnC();
                           memberOF = ""+member.next();
                       userPrincipalName=FindUser(memberOF,ADconn());
                       userPrincipalName=userPrincipalName.toUpperCase();
                       //userPrincipalName="'"+userPrincipalName+"'";
                       boolean c=find(userPrincipalName,st);
                           if (userPrincipalName!="")
                               {
                                if (!find(userPrincipalName,st)) 
                                {
                       String NameProced=NameProcedure(groupName,st);
                       String CallProced = "{ call "+NameProced+"(?) }";
                           try {
                       CallableStatement proc = C.prepareCall(CallProced);
                               proc.setString(1,userPrincipalName);  
                               proc.execute();
                               C.close(); 
                               }
                           catch (SQLException e) { e.printStackTrace();}
                                 }
                       //data[0]=memberOF;
                      // memberOF=memberOF.replaceAll(",DC=office,DC=elvis,DC=ru", "");
                       }
                   }
                      }
           //System.out.println("ROLE = "+role); 
           //CreateUserstables(groupName,Class1.find(groupName,st),st,role);
                       //k = k+1;
           
       }
        //System.out.println(k);
       }
    public static String FindUser(String arg,DirContext arg2) throws FileNotFoundException, IOException, NamingException {
        DirContext UserContext = arg2;
        SearchControls UserControls = new SearchControls();
        UserControls.setReturningAttributes(new String[] {"userPrincipalName"});
        UserControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
        NamingEnumeration results = UserContext.search(arg,"(&(objectCategory=user))", UserControls);
       //////////////////////////////////////////////////////////////////////////////
                  // Цикл по группам (Organisation Unit'ам) 
        int k =0;
           String userPrincipalName = "";
                  while (results != null && results.hasMoreElements()) 
                  {
                      SearchResult result = (SearchResult) results.next();
                      Attribute attribute = result.getAttributes().get("userPrincipalName");
                      if (attribute == null) {
                          continue;
                      }
                      String UserName = (String) attribute.get();
                       //String groupDN = (String) result.getAttributes().get( "distinguishedName").get();
                        //String memberOF = "";


           System.out.println("UsersName = "+UserName);
                      userPrincipalName = UserName;
       
                       
                    //  if (result.getAttributes().get("memberOf")!=null)
                   //   {
                    ///memberOF = (String) result.getAttributes().get( "memberOf").get();
                     ///     System.out.println("HROUPNAME = "+groupName+ " memberOF = "+memberOF);
                    //  }
           //CreateUserstables(groupName,Class1.find(groupName,st),st,role);
                      // k = k+1;
           
       }
       // System.out.println(k);
        return userPrincipalName;          
       }
    public static String NameProcedure(String arg,Statement arg2) throws SQLException {
       String query = "select PROCEDURE_NAME from GROUPS_PROCEDURE where GROUP_NAME = '"+arg+"'";
       ResultSet rs = arg2.executeQuery(query);
       String s="";
       while(rs.next())
       {
           
       //обработка результатов
           s = rs.getString(1);
           System.out.println(s);
        }
       return s;
    }
    public static Connection JDBCConnC() throws SQLException, FileNotFoundException, IOException {
          
    String user = PropertyReader("LoginDB");//Логин пользователя
    String password = PropertyReader("PasswordDB");//Пароль пользователя
    String url = PropertyReader("URLDB");//URL адрес
    String driver = "oracle.jdbc.OracleDriver";//Имя драйвера
    try {
    Class.forName("oracle.jdbc.OracleDriver");//Регистрируем драйвер
    } catch (ClassNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    Connection c = null;//Соединение с БД
    //подготавливаем запрос с параметрами
        
        c = DriverManager.getConnection (url, user, password);
             //Statement st = c.createStatement();
             //System.out.println("CONNECT");
             return c;
    } 
    public static DirContext ADconn() throws NamingException, FileNotFoundException, IOException 
    {
        Properties env = new Properties();
        env.setProperty(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
        env.setProperty(Context.PROVIDER_URL,PropertyReader("ldap"));
        env.setProperty(Context.SECURITY_PRINCIPAL, PropertyReader("ADlogin"));
        env.setProperty(Context.SECURITY_CREDENTIALS, PropertyReader("ADpassword"));
        
         DirContext UsersContext = new InitialDirContext(env);
         return UsersContext; 
    }
    public static boolean find(String args,Statement args3) throws SQLException
                             {
                                     //JDBCConn();
                                     String query = "select user_name from users where user_name = \'"+args+"\'";
                                     ResultSet rs = args3.executeQuery(query);
                                     String s = "";
                                    
                                     while(rs.next()){
                                         
                                     //обработка результатов
                                         s = rs.getString(1);
                                         //System.out.println(s);
                                                   }
                                    if (s =="")
                                    {
                                            return false;
                                        } else return true;
                                 }
}

при попытке запустить ругается что не находит драйвер оркл как запустить правельно???7при сборке вроде указал на драйвер
вот скрин



Автор: polosatij 25.7.2014, 01:47
нам не хватает Exception-а, чтоб дать вам какой-то путёвый совет..

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)