Пример #1
0
        public static Stream convert(java.io.Reader reader)
        {
            java.io.BufferedReader br = new java.io.BufferedReader(reader);

            String input = "";
            String line  = br.readLine();

            while (line != null)
            {
                input += java.lang.SystemJ.getProperty("line.separator")
                         + line;
                line = br.readLine();
            }
            MemoryStream memoryStream = new MemoryStream(Encoding.ASCII.GetBytes(input));

            return(memoryStream);
        }
Пример #2
0
        private static String readProviderFromFile()
        {//throws InternalError {
            java.lang.ClassLoader systemLoader = java.lang.ClassLoader.getSystemClassLoader();

            if (systemLoader != null)
            {
                java.io.InputStream inJ = systemLoader.getResourceAsStream("META-INF/services/java.util.prefs.PreferencesFactory"); //$NON-NLS-1$
                if (inJ != null)
                {
                    java.io.BufferedReader reader = new java.io.BufferedReader(new java.io.InputStreamReader(inJ));
                    String line = null;
                    try
                    {
                        while ((line = reader.readLine()) != null)
                        {
                            int index = line.indexOf("#"); //$NON-NLS-1$
                            // Trim comments
                            if (index != -1)
                            {
                                line = line.substring(0, index);
                            }
                            String trimedName = line.trim();
                            if (!"".equals(trimedName))
                            { //$NON-NLS-1$
                                return(trimedName);
                            }
                        }
                    }
                    catch (java.io.IOException e)
                    {
                        // prefs.11=Load provider configuration file faild: {0}
                        throw new java.lang.InternalError("Load provider configuration file faild: " + e);   //$NON-NLS-1$
                    }
                    finally
                    {
                        try
                        {
                            reader.close();
                        }
                        catch (java.io.IOException e)
                        {
                            // ignore
                        }
                    }
                }
            }
            return(null);
        }
Пример #3
0
        public static void readLongNames(String inputDataDir)
        {
            String fullPath, longNameRecord;

            String[]       fields;
            FieldTokenizer ft;

            java.io.File longColumnNameFile;
            dataDir = inputDataDir;
            java.io.BufferedReader longNameReader = (java.io.BufferedReader)null;
            fullPath           = dataDir + fileSep + "TINYSQL_LONG_COLUMN_NAMES.dat";
            longColumnNames    = new java.util.Vector <Object>();
            longColumnNameFile = new java.io.File(fullPath);
            if (longColumnNameFile.exists())
            {
                try
                {
                    longNameReader = new java.io.BufferedReader(new java.io.FileReader(fullPath));
                    while ((longNameRecord = longNameReader.readLine()) != null)
                    {
                        ft     = new FieldTokenizer(longNameRecord, '|', false);
                        fields = ft.getFields();
                        longColumnNames.addElement(fields[0]);
                        longColumnNames.addElement(fields[1]);
                    }
                    longNameReader.close();
                    longNamesInFileCount = longColumnNames.size() / 2;
                    if (debug)
                    {
                        java.lang.SystemJ.outJ.println("Long Names read: " + longNamesInFileCount);
                    }
                }
                catch (Exception readEx)
                {
                    java.lang.SystemJ.outJ.println("Reader exception " + readEx.getMessage());
                    longNamesInFileCount = 0;
                }
            }
        }
Пример #4
0
        /**
         * This method attempts to return the first line of the resource
         * META_INF/services/org.w3c.dom.DOMImplementationSourceList
         * from the provided ClassLoader.
         *
         * @param classLoader classLoader, may not be <code>null</code>.
         * @return first line of resource, or <code>null</code>
         */
        private static String getServiceValue(java.lang.ClassLoader classLoader)
        {
            String serviceId = "META-INF/services/" + PROPERTY;

            // try to find services in CLASSPATH
            try
            {
                java.io.InputStream input = getResourceAsStream(classLoader, serviceId);

                if (input != null)
                {
                    java.io.BufferedReader rd;
                    try
                    {
                        rd =
                            new java.io.BufferedReader(new java.io.InputStreamReader(input, "UTF-8"),
                                                       DEFAULT_LINE_LENGTH);
                    }
                    catch (java.io.UnsupportedEncodingException)
                    {
                        rd =
                            new java.io.BufferedReader(new java.io.InputStreamReader(input),
                                                       DEFAULT_LINE_LENGTH);
                    }
                    String serviceValue = rd.readLine();
                    rd.close();
                    if (serviceValue != null && serviceValue.length() > 0)
                    {
                        return(serviceValue);
                    }
                }
            }
            catch (Exception)
            {
                return(null);
            }
            return(null);
        }
Пример #5
0
        //throws ConfigurationError
        /*
         * Try to find provider using Jar Service Provider Mechanism
         *
         * @return instance of provider class if found or null
         */
        private static Object findJarServiceProvider(String factoryId)
        {
            String serviceId = "META-INF/services/" + factoryId;
            java.io.InputStream isJ = null;

            // First try the Context ClassLoader
            java.lang.ClassLoader cl = SecuritySupport.getContextClassLoader ();
            if (cl != null) {
                isJ = SecuritySupport.getResourceAsStream (cl, serviceId);

                // If no provider found then try the current ClassLoader
                if (isJ == null) {
                    cl = typeof(FactoryFinder).getClass ().getClassLoader ();
                    isJ = SecuritySupport.getResourceAsStream (cl, serviceId);
                }
            } else {
                // No Context ClassLoader, try the current
                // ClassLoader
                cl = typeof(FactoryFinder).getClass ().getClassLoader ();
                isJ = SecuritySupport.getResourceAsStream (cl, serviceId);
            }

            if (isJ == null) {
                // No provider found
                return null;
            }

            if (debug)
                dPrint ("found jar resource=" + serviceId +
                " using ClassLoader: " + cl);

            // Read the service provider name in UTF-8 as specified in
            // the jar spec.  Unfortunately this fails in Microsoft
            // VJ++, which does not implement the UTF-8
            // encoding. Theoretically, we should simply let it fail in
            // that case, since the JVM is obviously broken if it
            // doesn't support such a basic standard.  But since there
            // are still some users attempting to use VJ++ for
            // development, we have dropped in a fallback which makes a
            // second attempt using the platform's default encoding. In
            // VJ++ this is apparently ASCII, which is a subset of
            // UTF-8... and since the strings we'll be reading here are
            // also primarily limited to the 7-bit ASCII range (at
            // least, in English versions), this should work well
            // enough to keep us on the air until we're ready to
            // officially decommit from VJ++. [Edited comment from
            // jkesselm]
            java.io.BufferedReader rd;
            try {
                rd = new java.io.BufferedReader (new java.io.InputStreamReader (isJ, "UTF-8"), DEFAULT_LINE_LENGTH);
            } catch (java.io.UnsupportedEncodingException e) {
                rd = new java.io.BufferedReader (new java.io.InputStreamReader (isJ), DEFAULT_LINE_LENGTH);
            }

            String factoryClassName = null;
            try {
                // XXX Does not handle all possible input as specified by the
                // Jar Service Provider specification
                factoryClassName = rd.readLine ();
            } catch (java.io.IOException x) {
                // No provider found
                return null;
            } finally {
                try {
                    // try to close the reader.
                    rd.close ();
                }
            // Ignore the exception.
            catch (java.io.IOException exc) {
                }
            }

            if (factoryClassName != null &&
                     ! "".equals (factoryClassName)) {
                if (debug)
                    dPrint ("found in resource, value="
                    + factoryClassName);

                // Note: here we do not want to fall back to the current
                // ClassLoader because we want to avoid the case where the
                // resource file was found using one ClassLoader and the
                // provider class was instantiated using a different one.
                return newInstance (factoryClassName, cl, false);
            }

            // No provider found
            return null;
        }
Пример #6
0
            /*
             * Parse the provider-configuration file as specified
             * @see <a href="http://java.sun.com/j2se/1.5.0/docs/guide/jar/jar.html#Provider Configuration File">JAR File Specification</a>
             */
            private java.util.Set <String> parse(java.net.URL u)
            {
                java.io.InputStream    input  = null;
                java.io.BufferedReader reader = null;
                java.util.Set <String> names  = new java.util.HashSet <String>();
                try
                {
                    input  = u.openStream();
                    reader = new java.io.BufferedReader(new java.io.InputStreamReader(input, "utf-8")); //$NON-NLS-1$

                    String line;
                    while ((line = reader.readLine()) != null)
                    {
                        // The comment character is '#' (0x23)
                        // on each line all characters following the first comment character are ignored
                        int sharpIndex = line.indexOf('#');
                        if (sharpIndex >= 0)
                        {
                            line = line.substring(0, sharpIndex);
                        }

                        // Whitespaces are ignored
                        line = line.trim();

                        if (line.length() > 0)
                        {
                            // a java class name, check if identifier correct
                            char[] namechars = line.toCharArray();
                            for (int i = 0; i < namechars.Length; i++)
                            {
                                if (!(java.lang.Character.isJavaIdentifierPart(namechars[i]) || namechars[i] == '.'))
                                {
                                    throw new ServiceConfigurationError(Messages.getString("imageio.99", line));
                                }
                            }
                            names.add(line);
                        }
                    }
                }
                catch (java.io.IOException e)
                {
                    throw new ServiceConfigurationError(e.toString());
                }
                finally
                {
                    try
                    {
                        if (reader != null)
                        {
                            reader.close();
                        }
                        if (input != null)
                        {
                            input.close();
                        }
                    }
                    catch (java.io.IOException e)
                    {
                        throw new ServiceConfigurationError(e.toString());
                    }
                }

                return(names);
            }
Пример #7
0
        /*
         * Try to find provider using Jar Service Provider Mechanism
         *
         * @return instance of provider class if found or null
         */
        private static Object findJarServiceProvider(String factoryId)
        //throws ConfigurationError
        {
            String serviceId = "META-INF/services/" + factoryId;

            java.io.InputStream isJ = null;

            // First try the Context ClassLoader
            java.lang.ClassLoader cl = SecuritySupport.getContextClassLoader();
            if (cl != null)
            {
                isJ = SecuritySupport.getResourceAsStream(cl, serviceId);

                // If no provider found then try the current ClassLoader
                if (isJ == null)
                {
                    cl  = typeof(FactoryFinder).getClass().getClassLoader();
                    isJ = SecuritySupport.getResourceAsStream(cl, serviceId);
                }
            }
            else
            {
                // No Context ClassLoader, try the current
                // ClassLoader
                cl  = typeof(FactoryFinder).getClass().getClassLoader();
                isJ = SecuritySupport.getResourceAsStream(cl, serviceId);
            }

            if (isJ == null)
            {
                // No provider found
                return(null);
            }

            if (debug)
            {
                dPrint("found jar resource=" + serviceId +
                       " using ClassLoader: " + cl);
            }

            // Read the service provider name in UTF-8 as specified in
            // the jar spec.  Unfortunately this fails in Microsoft
            // VJ++, which does not implement the UTF-8
            // encoding. Theoretically, we should simply let it fail in
            // that case, since the JVM is obviously broken if it
            // doesn't support such a basic standard.  But since there
            // are still some users attempting to use VJ++ for
            // development, we have dropped in a fallback which makes a
            // second attempt using the platform's default encoding. In
            // VJ++ this is apparently ASCII, which is a subset of
            // UTF-8... and since the strings we'll be reading here are
            // also primarily limited to the 7-bit ASCII range (at
            // least, in English versions), this should work well
            // enough to keep us on the air until we're ready to
            // officially decommit from VJ++. [Edited comment from
            // jkesselm]
            java.io.BufferedReader rd;
            try {
                rd = new java.io.BufferedReader(new java.io.InputStreamReader(isJ, "UTF-8"), DEFAULT_LINE_LENGTH);
            } catch (java.io.UnsupportedEncodingException e) {
                rd = new java.io.BufferedReader(new java.io.InputStreamReader(isJ), DEFAULT_LINE_LENGTH);
            }

            String factoryClassName = null;

            try {
                // XXX Does not handle all possible input as specified by the
                // Jar Service Provider specification
                factoryClassName = rd.readLine();
            } catch (java.io.IOException x) {
                // No provider found
                return(null);
            } finally {
                try {
                    // try to close the reader.
                    rd.close();
                }
                // Ignore the exception.
                catch (java.io.IOException exc) {
                }
            }

            if (factoryClassName != null &&
                !"".equals(factoryClassName))
            {
                if (debug)
                {
                    dPrint("found in resource, value="
                           + factoryClassName);
                }

                // Note: here we do not want to fall back to the current
                // ClassLoader because we want to avoid the case where the
                // resource file was found using one ClassLoader and the
                // provider class was instantiated using a different one.
                return(newInstance(factoryClassName, cl, false));
            }

            // No provider found
            return(null);
        }
Пример #8
0
        public static void main(String[] args) //throws IOException,SQLException
        {
            java.sql.DatabaseMetaData  dbMeta;
            java.sql.ResultSetMetaData meta;
            java.sql.ResultSet         display_rs, typesRS;
            java.io.BufferedReader     stdin, loadFileReader;
            java.io.BufferedReader     startReader = (java.io.BufferedReader)null;
            String[]            fields;
            java.sql.Connection con;
            java.sql.Statement  stmt;
            FieldTokenizer      ft;

            java.sql.PreparedStatement pstmt = (java.sql.PreparedStatement)null;
            int i, rsColCount, endAt, colWidth, colScale, colPrecision, typeCount,
                colType, parameterIndex, b1, b2, parameterInt, startAt, columnIndex, valueIndex;
            String fName, tableName = null, inputString, cmdString, colTypeName, dbType,
                   parameterString, loadString, fieldString, readString;

            java.lang.StringBuffer lineOut, prepareBuffer, valuesBuffer, inputBuffer;
            bool echo = false;

            stdin = new java.io.BufferedReader(new java.io.InputStreamReader(java.lang.SystemJ.inJ));
            try
            {
                /*
                 *       Register the JDBC driver for dBase
                 */
                java.lang.Class.forName("com.sqlmagic.tinysql.dbfFileDriver");
            }
            catch (java.lang.ClassNotFoundException e)
            {
                java.lang.SystemJ.err.println(
                    "JDBC Driver could not be registered!!\n");
                if (TinySQLGlobals.DEBUG)
                {
                    e.printStackTrace();
                }
            }
            fName = ".";
            if (args.Length > 0)
            {
                fName = args[0];
            }

            /*
             *    Establish a connection to dBase
             */
            con = dbConnect(fName);
            if (con == (java.sql.Connection)null)
            {
                fName = ".";
                con   = dbConnect(fName);
            }
            dbMeta    = con.getMetaData();
            dbType    = dbMeta.getDatabaseProductName();
            dbVersion = dbMeta.getDatabaseProductVersion();
            java.lang.SystemJ.outJ.println("===================================================");
            java.lang.SystemJ.outJ.println(dbType + " Command line interface version "
                                           + dbVersion + " Java version released March 15, 2007");
            java.lang.SystemJ.outJ.println("Type HELP to get information on available commands.");
            cmdString   = "NULL";
            stmt        = con.createStatement();
            inputString = (String)null;
            if (args.Length > 1)
            {
                inputString = args[1].trim();
            }
            while (!cmdString.toUpperCase().equals("EXIT"))
            {
                try
                {
                    if (startReader != (java.io.BufferedReader)null)
                    {
                        /*
                         *             Command START files can contain comments and can have
                         *             commands broken over several lines.  However, they
                         *             cannot have partial commands on a line.
                         */
                        inputBuffer = new java.lang.StringBuffer();
                        inputString = (String)null;
                        while ((readString = startReader.readLine()) != null)
                        {
                            if (readString.startsWith("--") |
                                readString.startsWith("#"))
                            {
                                continue;
                            }
                            inputBuffer.append(readString + " ");

                            /*
                             *                A field tokenizer must be used to avoid problems with
                             *                semi-colons inside quoted strings.
                             */
                            ft = new FieldTokenizer(inputBuffer.toString(), ';', true);
                            if (ft.countFields() > 1)
                            {
                                inputString = inputBuffer.toString();
                                break;
                            }
                        }
                        if (inputString == (String)null)
                        {
                            startReader = (java.io.BufferedReader)null;
                            continue;
                        }
                    }
                    else if (args.Length == 0)
                    {
                        java.lang.SystemJ.outJ.print("tinySQL>");
                        inputString = stdin.readLine().trim();
                    }
                    if (inputString == (String)null)
                    {
                        break;
                    }
                    if (inputString.toUpperCase().startsWith("EXIT") |
                        inputString.toUpperCase().startsWith("QUIT"))
                    {
                        break;
                    }
                    startAt = 0;
                    while (startAt < inputString.length() - 1)
                    {
                        endAt = inputString.indexOf(";", startAt);
                        if (endAt == -1)
                        {
                            endAt = inputString.length();
                        }
                        cmdString = inputString.substring(startAt, endAt);
                        if (echo)
                        {
                            java.lang.SystemJ.outJ.println(cmdString);
                        }
                        startAt = endAt + 1;
                        if (cmdString.toUpperCase().startsWith("SELECT"))
                        {
                            display_rs = stmt.executeQuery(cmdString);
                            if (display_rs == (java.sql.ResultSet)null)
                            {
                                java.lang.SystemJ.outJ.println("Null ResultSet returned from query");
                                continue;
                            }
                            meta = display_rs.getMetaData();

                            /*
                             *                The actual number of columns retrieved has to be checked
                             */
                            rsColCount = meta.getColumnCount();
                            lineOut    = new java.lang.StringBuffer(100);
                            int[]    columnWidths     = new int[rsColCount];
                            int[]    columnScales     = new int[rsColCount];
                            int[]    columnPrecisions = new int[rsColCount];
                            int[]    columnTypes      = new int[rsColCount];
                            String[] columnNames      = new String[rsColCount];
                            for (i = 0; i < rsColCount; i++)
                            {
                                columnNames[i]      = meta.getColumnName(i + 1);
                                columnWidths[i]     = meta.getColumnDisplaySize(i + 1);
                                columnTypes[i]      = meta.getColumnType(i + 1);
                                columnScales[i]     = meta.getScale(i + 1);
                                columnPrecisions[i] = meta.getPrecision(i + 1);
                                if (columnNames[i].length() > columnWidths[i])
                                {
                                    columnWidths[i] = columnNames[i].length();
                                }
                                lineOut.append(padString(columnNames[i], columnWidths[i]) + " ");
                            }
                            if (TinySQLGlobals.DEBUG)
                            {
                                java.lang.SystemJ.outJ.println(lineOut.toString());
                            }
                            displayResults(display_rs);
                        }
                        else if (cmdString.toUpperCase().startsWith("CONNECT"))
                        {
                            con = dbConnect(cmdString.substring(8, cmdString.length()));
                        }
                        else if (cmdString.toUpperCase().startsWith("HELP"))
                        {
                            helpMsg(cmdString);
                        }
                        else if (cmdString.toUpperCase().startsWith("DESCRIBE"))
                        {
                            dbMeta     = con.getMetaData();
                            tableName  = cmdString.toUpperCase().substring(9);
                            display_rs = dbMeta.getColumns(null, null, tableName, null);
                            java.lang.SystemJ.outJ.println("\nColumns for table " + tableName + "\n"
                                                           + "Name                            Type");
                            while (display_rs.next())
                            {
                                lineOut = new java.lang.StringBuffer(100);
                                lineOut.append(padString(display_rs.getString(4), 32));
                                colTypeName  = display_rs.getString(6);
                                colType      = display_rs.getInt(5);
                                colWidth     = display_rs.getInt(7);
                                colScale     = display_rs.getInt(9);
                                colPrecision = display_rs.getInt(10);
                                if (colTypeName.equals("CHAR"))
                                {
                                    colTypeName = colTypeName + "("
                                                  + java.lang.Integer.toString(colWidth) + ")";
                                }
                                else if (colTypeName.equals("FLOAT"))
                                {
                                    colTypeName += "(" + java.lang.Integer.toString(colPrecision)
                                                   + "," + java.lang.Integer.toString(colScale) + ")";
                                }
                                lineOut.append(padString(colTypeName, 20) + padString(colType, 12));
                                java.lang.SystemJ.outJ.println(lineOut.toString());
                            }
                        }
                        else if (cmdString.toUpperCase().equals("SHOW TABLES"))
                        {
                            for (i = 0; i < tableList.size(); i++)
                            {
                                java.lang.SystemJ.outJ.println((String)tableList.elementAt(i));
                            }
                        }
                        else if (cmdString.toUpperCase().equals("SHOW TYPES"))
                        {
                            typesRS   = dbMeta.getTypeInfo();
                            typeCount = displayResults(typesRS);
                        }
                        else if (cmdString.toUpperCase().startsWith("SET "))
                        {
                            /*
                             *                Support for SET DEBUG ON/OFF and SET ECHO ON/OFF
                             */
                            ft     = new FieldTokenizer(cmdString.toUpperCase(), ' ', false);
                            fields = ft.getFields();
                            if (fields[1].equals("ECHO"))
                            {
                                if (fields[2].equals("ON"))
                                {
                                    echo = true;
                                }
                                else
                                {
                                    echo = false;
                                }
                            }
                            else if (fields[1].equals("DEBUG"))
                            {
                                if (fields[2].equals("ON"))
                                {
                                    TinySQLGlobals.DEBUG = true;
                                }
                                else
                                {
                                    TinySQLGlobals.DEBUG = false;
                                }
                            }
                            else if (fields[1].equals("PARSER_DEBUG"))
                            {
                                if (fields[2].equals("ON"))
                                {
                                    TinySQLGlobals.PARSER_DEBUG = true;
                                }
                                else
                                {
                                    TinySQLGlobals.PARSER_DEBUG = false;
                                }
                            }
                            else if (fields[1].equals("WHERE_DEBUG"))
                            {
                                if (fields[2].equals("ON"))
                                {
                                    TinySQLGlobals.WHERE_DEBUG = true;
                                }
                                else
                                {
                                    TinySQLGlobals.WHERE_DEBUG = false;
                                }
                            }
                            else if (fields[1].equals("EX_DEBUG"))
                            {
                                if (fields[2].equals("ON"))
                                {
                                    TinySQLGlobals.EX_DEBUG = true;
                                }
                                else
                                {
                                    TinySQLGlobals.EX_DEBUG = false;
                                }
                            }
                        }
                        else if (cmdString.toUpperCase().startsWith("SPOOL "))
                        {
                            /*
                             *                Spool output to a file.
                             */
                            ft    = new FieldTokenizer(cmdString, ' ', false);
                            fName = ft.getField(1);
                            if (fName.equals("OFF"))
                            {
                                try
                                {
                                    spoolFileWriter.close();
                                }
                                catch (Exception spoolEx)
                                {
                                    java.lang.SystemJ.outJ.println("Unable to close spool file "
                                                                   + spoolEx.getMessage() + newLine);
                                }
                            }
                            else
                            {
                                try
                                {
                                    spoolFileWriter = new java.io.FileWriter(fName);
                                    if (spoolFileWriter != (java.io.FileWriter)null)
                                    {
                                        java.lang.SystemJ.outJ.println("Output spooled to " + fName);
                                    }
                                }
                                catch (Exception spoolEx)
                                {
                                    java.lang.SystemJ.outJ.println("Unable to spool to file "
                                                                   + spoolEx.getMessage() + newLine);
                                }
                            }
                        }
                        else if (cmdString.toUpperCase().startsWith("START "))
                        {
                            ft    = new FieldTokenizer(cmdString, ' ', false);
                            fName = ft.getField(1);
                            if (!fName.toUpperCase().endsWith(".SQL"))
                            {
                                fName += ".SQL";
                            }
                            try
                            {
                                startReader = new java.io.BufferedReader(new java.io.FileReader(fName));
                            }
                            catch (Exception)
                            {
                                startReader = (java.io.BufferedReader)null;
                                throw new TinySQLException("No such file: " + fName);
                            }
                        }
                        else if (cmdString.toUpperCase().startsWith("LOAD"))
                        {
                            ft         = new FieldTokenizer(cmdString, ' ', false);
                            fName      = ft.getField(1);
                            tableName  = ft.getField(3);
                            display_rs = stmt.executeQuery("SELECT * FROM " + tableName);
                            meta       = display_rs.getMetaData();
                            rsColCount = meta.getColumnCount();

                            /*
                             *                Set up the PreparedStatement for the inserts
                             */
                            prepareBuffer = new java.lang.StringBuffer("INSERT INTO " + tableName);
                            valuesBuffer  = new java.lang.StringBuffer(" VALUES");
                            for (i = 0; i < rsColCount; i++)
                            {
                                if (i == 0)
                                {
                                    prepareBuffer.append(" (");
                                    valuesBuffer.append(" (");
                                }
                                else
                                {
                                    prepareBuffer.append(",");
                                    valuesBuffer.append(",");
                                }
                                prepareBuffer.append(meta.getColumnName(i + 1));
                                valuesBuffer.append("?");
                            }
                            prepareBuffer.append(")" + valuesBuffer.toString() + ")");
                            try
                            {
                                pstmt          = con.prepareStatement(prepareBuffer.toString());
                                loadFileReader = new java.io.BufferedReader(new java.io.FileReader(fName));
                                while ((loadString = loadFileReader.readLine()) != null)
                                {
                                    if (loadString.toUpperCase().equals("ENDOFDATA"))
                                    {
                                        break;
                                    }
                                    columnIndex = 0;
                                    valueIndex  = 0;
                                    ft          = new FieldTokenizer(loadString, '|', true);
                                    while (ft.hasMoreFields())
                                    {
                                        fieldString = ft.nextField();
                                        if (fieldString.equals("|"))
                                        {
                                            columnIndex++;
                                            if (columnIndex > valueIndex)
                                            {
                                                pstmt.setString(valueIndex + 1, (String)null);
                                                valueIndex++;
                                            }
                                        }
                                        else if (columnIndex < rsColCount)
                                        {
                                            pstmt.setString(valueIndex + 1, fieldString);
                                            valueIndex++;
                                        }
                                    }
                                    pstmt.executeUpdate();
                                }
                                pstmt.close();
                            }
                            catch (Exception loadEx)
                            {
                                java.lang.SystemJ.outJ.println(loadEx.getMessage());
                            }
                        }
                        else if (cmdString.toUpperCase().startsWith("SETSTRING") |
                                 cmdString.toUpperCase().startsWith("SETINT"))
                        {
                            b1 = cmdString.indexOf(" ");
                            b2 = cmdString.lastIndexOf(" ");
                            if (b2 > b1 & b1 > 0)
                            {
                                parameterIndex  = java.lang.Integer.parseInt(cmdString.substring(b1 + 1, b2));
                                parameterString = cmdString.substring(b2 + 1);
                                if (TinySQLGlobals.DEBUG)
                                {
                                    java.lang.SystemJ.outJ.println("Set parameter["
                                                                   + parameterIndex + "]=" + parameterString);
                                }
                                if (cmdString.toUpperCase().startsWith("SETINT"))
                                {
                                    parameterInt = java.lang.Integer.parseInt(parameterString);
                                    pstmt.setInt(parameterIndex, parameterInt);
                                }
                                else
                                {
                                    pstmt.setString(parameterIndex, parameterString);
                                }
                                if (parameterIndex == 2)
                                {
                                    pstmt.executeUpdate();
                                }
                            }
                        }
                        else
                        {
                            if (cmdString.indexOf("?") > -1)
                            {
                                pstmt = con.prepareStatement(cmdString);
                            }
                            else
                            {
                                try
                                {
                                    stmt.executeUpdate(cmdString);
                                    java.lang.SystemJ.outJ.println("DONE\n");
                                }
                                catch (java.lang.Exception upex)
                                {
                                    java.lang.SystemJ.outJ.println(upex.getMessage());
                                    if (TinySQLGlobals.DEBUG)
                                    {
                                        upex.printStackTrace();
                                    }
                                }
                            }
                        }
                    }
                    if (args.Length > 1)
                    {
                        cmdString = "EXIT";
                    }
                }
                catch (java.sql.SQLException te)
                {
                    java.lang.SystemJ.outJ.println(te.getMessage());
                    if (TinySQLGlobals.DEBUG)
                    {
                        te.printStackTrace(java.lang.SystemJ.outJ);
                    }
                    inputString = (String)null;
                }
                catch (Exception e)
                {
                    java.lang.SystemJ.outJ.println(e.getMessage());
                    cmdString = "EXIT";
                    break;
                }
            }
            try
            {
                if (spoolFileWriter != (java.io.FileWriter)null)
                {
                    spoolFileWriter.close();
                }
            }
            catch (Exception spoolEx)
            {
                java.lang.SystemJ.outJ.println("Unable to close spool file "
                                               + spoolEx.getMessage() + newLine);
            }
        }
Пример #9
0
        //throws SAXException
        /**
         * Attempt to create an XMLReader from system defaults.
         * In environments which can support it, the name of the XMLReader
         * class is determined by trying each these options in order, and
         * using the first one which succeeds:<p/> <ul>
         *
         * <li>If the system property <code>org.xml.sax.driver</code>
         * has a value, that is used as an XMLReader class name. </li>
         *
         * <li>The JAR "Services API" is used to look for a class name
         * in the <em>META-INF/services/org.xml.sax.driver</em> file in
         * jarfiles available to the runtime.</li>
         *
         * <li> SAX parser distributions are strongly encouraged to provide
         * a default XMLReader class name that will take effect only when
         * previous options (on this list) are not successful.</li>
         *
         * <li>Finally, if {@link ParserFactory#makeParser()} can
         * return a system default SAX1 parser, that parser is wrapped in
         * a {@link ParserAdapter}.  (This is a migration aid for SAX1
         * environments, where the <code>org.xml.sax.parser</code> system
         * property will often be usable.) </li>
         *
         * </ul>
         *
         * <p> In environments such as small embedded systems, which can not
         * support that flexibility, other mechanisms to determine the default
         * may be used. </p>
         *
         * <p>Note that many Java environments allow system properties to be
         * initialized on a command line.  This means that <em>in most cases</em>
         * setting a good value for that property ensures that calls to this
         * method will succeed, except when security policies intervene.
         * This will also maximize application portability to older SAX
         * environments, with less robust implementations of this method.
         * </p>
         *
         * @return A new XMLReader.
         * @exception org.xml.sax.SAXException If no default XMLReader class
         *            can be identified and instantiated.
         * @see #createXMLReader(java.lang.String)
         */
        public static XMLReader createXMLReader()
        {
            String		className = null;
            java.lang.ClassLoader	loader = NewInstance.getClassLoader ();

            // 1. try the JVM-instance-wide system property
            try { className = java.lang.SystemJ.getProperty (property); }
            catch (java.lang.RuntimeException e) { /* normally fails for applets */ }

            // 2. if that fails, try META-INF/services/
            if (className == null) {
            try {
            String		service = "META-INF/services/" + property;
            java.io.InputStream	input;
            java.io.BufferedReader	reader;

            if (loader == null)
            input = java.lang.ClassLoader.getSystemResourceAsStream (service);
            else
            input = loader.getResourceAsStream (service);

            if (input != null) {
            reader = new java.io.BufferedReader (
                new java.io.InputStreamReader (input, "UTF8"));
            className = reader.readLine ();
            input.close ();
            }
            } catch (Exception e) {
            }
            }

            // 3. Distro-specific fallback
            if (className == null) {
            // BEGIN DISTRIBUTION-SPECIFIC

            // EXAMPLE:
            // className = "com.example.sax.XmlReader";
            // or a $JAVA_HOME/jre/lib/*properties setting...

            //Take a look in Java 7 shows: className = "com.sun.org.apache.xerces.internal.parsers.SAXParser";

            // END DISTRIBUTION-SPECIFIC
            }

            // do we know the XMLReader implementation class yet?
            if (className != null)
            return loadClass (loader, className);

            // 4. panic -- adapt any SAX1 parser
            try {
            return new ParserAdapter (ParserFactory.makeParser ());
            } catch (java.lang.Exception e) {
            throw new SAXException ("Can't create default XMLReader; "
            + "is system property org.xml.sax.driver set?");
            }
        }
Пример #10
0
        /*
         * Attempt to create an XMLReader from system defaults.
         * In environments which can support it, the name of the XMLReader
         * class is determined by trying each these options in order, and
         * using the first one which succeeds:<p/> <ul>
         *
         * <li>If the system property <code>org.xml.sax.driver</code>
         * has a value, that is used as an XMLReader class name. </li>
         *
         * <li>The JAR "Services API" is used to look for a class name
         * in the <em>META-INF/services/org.xml.sax.driver</em> file in
         * jarfiles available to the runtime.</li>
         *
         * <li> SAX parser distributions are strongly encouraged to provide
         * a default XMLReader class name that will take effect only when
         * previous options (on this list) are not successful.</li>
         *
         * <li>Finally, if {@link ParserFactory#makeParser()} can
         * return a system default SAX1 parser, that parser is wrapped in
         * a {@link ParserAdapter}.  (This is a migration aid for SAX1
         * environments, where the <code>org.xml.sax.parser</code> system
         * property will often be usable.) </li>
         *
         * </ul>
         *
         * <p> In environments such as small embedded systems, which can not
         * support that flexibility, other mechanisms to determine the default
         * may be used. </p>
         *
         * <p>Note that many Java environments allow system properties to be
         * initialized on a command line.  This means that <em>in most cases</em>
         * setting a good value for that property ensures that calls to this
         * method will succeed, except when security policies intervene.
         * This will also maximize application portability to older SAX
         * environments, with less robust implementations of this method.
         * </p>
         *
         * @return A new XMLReader.
         * @exception org.xml.sax.SAXException If no default XMLReader class
         *            can be identified and instantiated.
         * @see #createXMLReader(java.lang.String)
         */
        public static XMLReader createXMLReader()
        //throws SAXException
        {
            String className = null;

            java.lang.ClassLoader loader = NewInstance.getClassLoader();

            // 1. try the JVM-instance-wide system property
            try { className = java.lang.SystemJ.getProperty(property); }
            catch (java.lang.RuntimeException e) { /* normally fails for applets */ }

            // 2. if that fails, try META-INF/services/
            if (className == null)
            {
                try {
                    String service = "META-INF/services/" + property;
                    java.io.InputStream    input;
                    java.io.BufferedReader reader;

                    if (loader == null)
                    {
                        input = java.lang.ClassLoader.getSystemResourceAsStream(service);
                    }
                    else
                    {
                        input = loader.getResourceAsStream(service);
                    }

                    if (input != null)
                    {
                        reader = new java.io.BufferedReader(
                            new java.io.InputStreamReader(input, "UTF8"));
                        className = reader.readLine();
                        input.close();
                    }
                } catch (Exception e) {
                }
            }

            // 3. Distro-specific fallback
            if (className == null)
            {
// BEGIN DISTRIBUTION-SPECIFIC

                // EXAMPLE:
                // className = "com.example.sax.XmlReader";
                // or a $JAVA_HOME/jre/lib/*properties setting...

                //Take a look in Java 7 shows: className = "com.sun.org.apache.xerces.internal.parsers.SAXParser";

// END DISTRIBUTION-SPECIFIC
            }

            // do we know the XMLReader implementation class yet?
            if (className != null)
            {
                return(loadClass(loader, className));
            }

            // 4. panic -- adapt any SAX1 parser
            try {
                return(new ParserAdapter(ParserFactory.makeParser()));
            } catch (java.lang.Exception e) {
                throw new SAXException("Can't create default XMLReader; "
                                       + "is system property org.xml.sax.driver set?");
            }
        }