logo
down
shadow

How to setup database on tomcat start


How to setup database on tomcat start

By : user2952745
Date : November 19 2020, 01:01 AM
wish help you to fix your issue After a little bit of research I came to solution that uses ServletContextListener. I'll skip explanation and show you the code.
code :
@WebListener
public class DatabaseCreator implements ServletContextListener {

    protected final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Resource(
            name = "jdbc/rssDS",
            type = javax.sql.DataSource.class,
            authenticationType = Resource.AuthenticationType.CONTAINER
    )
    private DataSource dataSource;

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        if (dataSource == null) {
            logger.error("Data source wasn't initialized");
        }
        String sql = readStreamToString(sce.getServletContext());
        if (StringUtils.isBlank(sql)) {
            logger.error("SQL script is empty");
        }
        try {
            logger.debug("Executing SQL script");
            Connection connection = dataSource.getConnection();
            Statement statement = connection.createStatement();
            statement.execute(sql);
        } catch (SQLException e) {
            logger.error("Unable to create database table structure", e);
        }
    }

    private String readStreamToString(ServletContext ctx) {
        //skipped, reads stream contents into String
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {

    }
}


Share : facebook icon twitter icon
What's the underlying difference of normally start tomcat and debug start tomcat?

What's the underlying difference of normally start tomcat and debug start tomcat?


By : amir sarhang
Date : March 29 2020, 07:55 AM
it should still fix some issue In debug mode you can set breakpoints, so the JVM will pause there and using that, if you are in the debug perspective, you can then see all the variables, this is useful if you are getting an error or you don't know why a certain variable is null, for example.
Unable to deploy Tomcat Manager in Security-Hardened Tomcat 8 (SEVERE: ContainerBase.addChild: start: Failed to start co

Unable to deploy Tomcat Manager in Security-Hardened Tomcat 8 (SEVERE: ContainerBase.addChild: start: Failed to start co


By : Mahmudul Hasan Nahid
Date : March 29 2020, 07:55 AM
like below fixes the issue Here's how it was fixed:
After Tomcat Manager is set up, copy %CATALINA_BASE%\webapps\manager\META-INF\context.xml to %CATALINA_BASE%\conf\Catalina\localhost\manager.xml
Setup database connection with tomcat 7

Setup database connection with tomcat 7


By : sankar M
Date : March 29 2020, 07:55 AM
To fix the issue you can do You have to create a dataSource with JNDI :
First, in your spring bean configuration (spring-database.xml) add this :
code :
 <beans:bean id="dbDataSource"  class="org.springframework.jndi.JndiObjectFactoryBean">
    <beans:property name="jndiName" value="java:comp/env/jdbc/myDB"/>
</beans:bean>
<Resource name="jdbc/globalDB"
  global="jdbc/globalDB"
  auth="Container"
  type="javax.sql.DataSource"
  driverClassName="com.mysql.jdbc.Driver"
  url="jdbc:mysql://localhost:3306/sailplanner"
  username="sailplanner"
  password="sailplanner2"/>
<ResourceLink name="jdbc/myDB"
                global="jdbc/globalDB"
                auth="Container"
                type="javax.sql.DataSource" />
Why tomcat wont start with Failed to start apache tomcat web server tomcat.service: Control process exited, code=exited

Why tomcat wont start with Failed to start apache tomcat web server tomcat.service: Control process exited, code=exited


By : Dmitriy Dya
Date : March 29 2020, 07:55 AM
Hope that helps How i tried to reproduce:
I followed the tutorial on a fresh virtual box on ubuntu 16.04.
Tomcat start failure probably due to Linux network setup: java.net.BindException: Cannot assign requested address

Tomcat start failure probably due to Linux network setup: java.net.BindException: Cannot assign requested address


By : Guy Zuntz
Date : March 29 2020, 07:55 AM
it should still fix some issue Seems to me that your /etc/host configuration is not correct. Are you able to ping 127.0.0.1? Also make sure you have following line in your host file
/etc/host
Related Posts Related Posts :
  • No address associated with hostname using vagrant
  • 2 way data-binding between a polymer component and a model?
  • How can I rename an already published app in the Windows Dev Center?
  • Using Chef 12 , Chef Client unable to connect to chef Server
  • GCM notification not working (GoogleCloudMessaging)
  • Measured GFLOPS is greater then theoretical GFLOPS
  • Progress ABL - strip and add to temp table
  • Errors occuring when make-ing Aircrack-ng on raspberry pi
  • Detecting Handedness from Device Use
  • Query a manual list of data items
  • Similar to pivot - Windows 8.1 Desktop app
  • CKEDITOR And Styles configuration with only toolbar
  • Segmentation fault due to data alignment issue on MIC
  • how to connect a Java app ( java code ) to cloudant?
  • How to download a file/folder from remote (openshift) to local system
  • Where can i find customeditors in JBPM 6
  • Pig get distinct rows with counts
  • In Flex when is yylineno updated?
  • How does a semantic reasoner for protegé is made?
  • how to stop another rows to be select after select a row in uitableview
  • Setup cmd.exe parameter when starting ConEmu
  • WPF how to get the same visual size in different devices
  • How to convert tiff to searchable pdf using alfresco and tesseact?
  • Intel Media SDK: Regarding mfxIMPL Usage
  • How to pass values to SOAP service using web service consumer?
  • Post image base64 from iOS to twitter using request.js
  • I have installed chef server, client version 12.0.1 and 12.0.3 respectively but unable to authenticate to chef server
  • Minifying and publishing CSS and JavaScript using Visual Studio 2013 and LESS
  • Can't deploy kitchensink example
  • Facing issue in mule testing
  • db2 explain result about lock size
  • Make Firebug NOT autocomplete
  • Blank Space at bottom of Polymer Paper Dialog
  • How do you initialize application state at startup and access it from controllers in MVC 6?
  • can you help when to use field and when to use parameter and variable in jasper?
  • What are Talend change data capture's pluses and deltas in a production EAI+big data integration scenario?
  • Tree traversal in Rust vs Borrow Checker
  • how sensiya SDK distinct motion sitting and driving?
  • Test Dropbox webhooks implementation with self-signed certificate?
  • Custom axis labels for Core Plot
  • Using CLLocationManager in SpringBoard, but got the error with:depending on legacy on-demand authorization, which is not
  • retrieving selected documents in couchdb
  • How to unroll client side bundle
  • Why JPanel doesn't have all the lines in my app?
  • make ctrl+enter add semicolon to the end of the line
  • How to test low-bit ambient and burn-in protection when making watch faces?
  • What is causing this error in changing the default music font in a Lilypond document?
  • Using environment variables in POST payload
  • Use a custom helper in Middleman Frontmatter
  • LinkedIn r_basicprofile and r_fullprofile scope fields and why are both "redundant"?
  • Disconnecting 2 vertical "lines" with glDrawArrays GL_TRIANGLE_STRIP
  • Slow apigee query when using geolocation with wildcard search
  • Allocator replacement check
  • Javafx 8 how to make mouse cursor invisible?
  • Can you use OpenID Connect without obtaining OAuth credentials?
  • Appium send_keys overwritting previous text
  • Where do I find my google places 'place_id'?
  • Parse.com Stripe: Creating a charge that is not captured
  • Custom Vibe sequence in Pebble.js?
  • reuse property in my own owl ontology but change domain/range
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org