Translate

Friday, October 15, 2021

Tomcat - Unable to locate persistence units error

I recently was working on updating the libraries for a Java web application and was unable to connect to the database. Stepping through the program in Tomcat I saw that it was giving me the "Unable to locate persistence units" error. This puzzled me for a long time, so I decided to take a closer look as I stepped through the application. The actual error message in the exception was "unrecognized persistence.xml version 2.2"! So I reverted back to version 2.1!

Tomcat - Service will not start, incorrect function error in Windows System Log

The Tomcat service would not start. I checked the Windows System Log and found the following error.
This was caused by Java version on the system not matching the Java version in Tomcat. Check the current Java version in Windows by opening a command prompt and executing "Java - version". Then check the version in Tomcat by executing Tomcat#w.exe, where # is the Tomcat version number, located in the bin folder under your Tomcat install. Check the Java tab and check the entry for Java Virtual Machine. These are my settings with the corrected setting in Tomcat:

Monday, September 20, 2021

TSQL - Simple Recursive Example

I needed to change a field in a table that holds the tree structure for menues in Unit4 ERP. The fields involved were the parent_menu_id, menu_id, and client. So parent_menu_id would be the folder, menu_id would be the folders or menu item, and client is the field to be updated. The paren_menu_id at top of the tree is REP05. This is the update query.

WITH RecQry AS
(
    SELECT aagM.menu_id
      FROM aagmenu aagM where parent_menu_id = 'REP05'
    UNION ALL
    SELECT Child.menu_id
      FROM RecQry PARENT, aagmenu CHILD
        where CHILD.parent_menu_id = PARENT.menu_id
)
update aagmenu
set client = '*'
where menu_id in
(
select menu_id from RecQry
)

Monday, August 23, 2021

TSQL - Assign A Sequential Number To Each Record In A Group

I needed to insert records from one table into another table and add a sequential number, field seq, that was group on an id field, GroupId. This CTE was the eastiest way that I found to add the number.

UPDATE t
SET seq = GROUPSEQ
FROM (SELECT seq, [GroupId], row_number() OVER (PARTITION BY [GroupId] ORDER BY [GroupId]) GROUPSEQ
FROM [TableMemo]) t

Wednesday, August 18, 2021

TSQL - Add a Sequential Number Field

I needed to insert records from one table into another table and add a sequential number that started at a certain value. This was the eastiest way that I found to add the number. Just add an int field to the source table and add the values using an update. So in the following code, id was the int field that I created, and I add numbers begining with 6001.

DECLARE @id INT 
SET @id = 6000
UPDATE Table 
SET @id = id = @id + 1 

Sunday, September 25, 2016

Word - Mail Merge a Document to Separate Files

I was asked to help mail merge a document and save the result to a file name based using values from the some merged fields. I found some code on Stack Overflow by Søren Francis and modified it to loop.
My steps:

Sub OutDoc()
'
' 1) Merges active record and saves the resulting document named by the datafield
' 2) Closes the resulting document, and advances to the next record in the datasource
'
' Based on code by Søren Francis 6/7-2013 at href="http://stackoverflow.com/questions/12594828/how-to-split-a-mail-merge-and-save-files-with-a-merge-field-as-the-name
   
    Dim DokName  As String   'ADDED CODE
    Dim strFolder As String
    Dim fDone As Boolean
    fDone = False
    ' Set the destination folder
    strFolder = "C:\Projects\ForAdam\FinalDocs\"
 ' Start at the first document
 ActiveDocument.MailMerge.DataSource.ActiveRecord = wdFirstRecord
  Do
    With ActiveDocument.MailMerge
        .Destination = wdSendToNewDocument
        .SuppressBlankLines = True
        With .DataSource
            .FirstRecord = ActiveDocument.MailMerge.DataSource.ActiveRecord
            .LastRecord = ActiveDocument.MailMerge.DataSource.ActiveRecord
    ' Set the document name
           DokName = .DataFields("ResID").Value & .DataFields("First").Value & "_Contract"
        End With

    ' Merge the active record
        .Execute Pause:=False
    End With

    ' Save then resulting document. NOTICE MODIFIED filename
    ActiveDocument.SaveAs2 FileName:=strFolder + DokName + ".doc", FileFormat:= _
        wdFormatDocument, LockComments:=False, Password:="", AddToRecentFiles _
        :=True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts _
        :=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
        SaveAsAOCELetter:=False

    ' Close the resulting document
    ActiveWindow.Close

    ' Now, back in the template document, advance to next record if there is a next record
    If ActiveDocument.MailMerge.DataSource.ActiveRecord <> ActiveDocument.MailMerge.DataSource.RecordCount Then
        ActiveDocument.MailMerge.DataSource.ActiveRecord = wdNextRecord
    Else ' Flag that we are done
        fDone = True
    End If
  Loop Until fDone 
End Sub

Friday, April 15, 2016

Tomcat - Update SSL certificate

I spent the day updating the server certificate with new certificates from Godaddy to provide a more secure connection to the site. Adding the new cert to IIS was a snap but adding it to Tomcat just wasn't working. I was finally able to get it to work by following the information located here. Basically I just exported the certificate from the certificate store on the IIS server as a pfx file.

My connector setting in the Tomcat server.xml file:

<Connector port="8443" connectionLinger="20000" connectionTimeout="60000" protocol="HTTP/1.1" keystoreType="PKCS12" keystorePass="youwish" keystoreFile="webapps/iis_export.pfx" sslProtocol="TLS" clientAuth="false" disableUploadTimeout="true" enableLookups="true" secure="true" scheme="https" maxThreads="150" SSLEnabled="true"/>