GithubHelp home page GithubHelp logo

jdbcwriter didn't work about tinylog HOT 7 CLOSED

tinylog-org avatar tinylog-org commented on May 25, 2024
jdbcwriter didn't work

from tinylog.

Comments (7)

pmwmedia avatar pmwmedia commented on May 25, 2024

Can you try to add the line Class.forName("com.mysql.jdbc.Driver").newInstance(); straight before configuring tinylog via the configurator class. Please exclude temporarily tinylog.properties for this test if existing.

For example:

Class.forName("com.mysql.jdbc.Driver").newInstance();
Configurator.defaultConfig()
   .writer(new JdbcWriter("jdbc:mysql://10.211.55.5:3306/DATABASE", "TABLE", Arrays.asList(Value.MESSAGE)))
   .activate();

Please let me know whether this works?

from tinylog.

 avatar commented on May 25, 2024

I tried as you recommended. I got following error:

Loading class com.mysql.jdbc.Driver'. This is deprecated. The new driver class iscom.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.

I  skipped the Class.forName("com.mysql.jdbc.Driver").newInstance(); but the same error still occur. So I think you internally called this driver. My environment is JDBC4 and Java 1.8, mysql connector is 5.1.38. My feeling is that tinylog can’t run in this environment with jdbcwriter, right?

Also, how can i set the user and password for the connection. I tried to attach &user=XXX&password=YYY to the jdbc url. 

Kind Regards

hjlabrador

Absender: Martin Winandy [email protected]
Antworten: pmwmedia/tinylog [email protected]
Datum: 29. April 2016 at 17:18:57
Empfänger: pmwmedia/tinylog [email protected]
CC: hjlabrador [email protected], Author [email protected]
Betreff:  Re: [pmwmedia/tinylog] jdbcwriter didn't work (#30)

Can you try to add the line Class.forName("com.mysql.jdbc.Driver").newInstance(); straight before configuring tinylog via the configurator class. Please exclude temporarily tinylog.properties for this test if existing.

For example:

Class.forName("com.mysql.jdbc.Driver").newInstance();
Configurator.defaultConfig()
.writer(new JdbcWriter("jdbc:mysql://10.211.55.5:3306/DATABASE", "TABLE", Arrays.asList(Value.MESSAGE)))
.activate();

Please let me know whether this works?


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub

from tinylog.

pmwmedia avatar pmwmedia commented on May 25, 2024

JdbcWriter just calls DriverManager.getConnection(url) (see: JdbcWriter.java:319). This is standard Java API and should work also on your environment. Actually JdbcWriter is used quite often together with MySQL. What happens if you call DriverManager.getConnection(url) directly?

You can pass username and password via arguments: Javadoc JdbcWriter. But ?user=X&password=Y should work as well.

Can you share a small example project for reproducing the issue? Without example code I can just guess.

from tinylog.

 avatar commented on May 25, 2024

So, I could get it to work with Class.forName("com.mysql.jdbc.Driver").newInstance(); ahead the Configurator as you recommended. However with tinylog.properties I still have the problem that the driver could not be found. Maybe you have an idea about your implementation. So far I can go on with my project, however the properties is a better way for configuration.

HJLabrador

Kind Regards

Absender: Martin Winandy [email protected]
Antworten: pmwmedia/tinylog [email protected]
Datum: 30. April 2016 at 11:58:02
Empfänger: pmwmedia/tinylog [email protected]
CC: hjlabrador [email protected], Author [email protected]
Betreff:  Re: [pmwmedia/tinylog] jdbcwriter didn't work (#30)

JdbcWriter just calls DriverManager.getConnection(url) (see: JdbcWriter.java:319). This is standard Java API and should work also on your environment. Actually JdbcWriter is used quite often together with MySQL. What happens if you call DriverManager.getConnection(url) directly?

You can pass username and password via arguments: Javadoc JdbcWriter. But ?user=X&password=Y should work as well.

Can you share a small example project for reproducing the issue? Without example code I can just guess.


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub

from tinylog.

pmwmedia avatar pmwmedia commented on May 25, 2024

I have set up a new tomcat installation from scratch. Now I'm able to reproduce the problem. Out of the box, tomcat can't load driver services. You have either to create an instance of the driver or to declare a data source. I plan to support data sources in tinylog 1.2. Help is welcome for the implementation :-)

For tinylog 1.1, I propose to load the driver via a WebListener:

@WebListener
public class LifeCycleListener implements ServletContextListener {

    @Override
    public void contextInitialized(ServletContextEvent event) {
        try {
            new com.mysql.jdbc.Driver();
        } catch (SQLException e) {
            Logger.error(e);
        }
    }

    @Override
    public void contextDestroyed(ServletContextEvent event) {
    }

}

The configuration can be loaded from tinylog.properties. You don't need to use the configurator class. It is only imported that the JDBC driver is loaded before any logger call.

from tinylog.

pmwmedia avatar pmwmedia commented on May 25, 2024

Fixed in tinylog 1.2 branch by supporting DataSources

from tinylog.

github-actions avatar github-actions commented on May 25, 2024

This closed issue has been locked automatically. However, please feel free to file a new issue.

from tinylog.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.