question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`JdbcAspect.getConnection` will execute `SELECT USER()` every time

See original GitHub issue

I find the getConnection() method is slower than expected. So I check the source code:

  public Object getConnection(final ProceedingJoinPoint pjp) throws Throwable {
    Connection conn = (Connection) pjp.proceed();
    String url = conn.getMetaData().getURL();
    String user = conn.getMetaData().getUserName();
    String dbType;
    boolean withActiveSpanOnly = false;
    try {
      dbType = url.split(":")[1];
    } catch (Throwable t) {
      throw new IllegalArgumentException(
          "Invalid JDBC URL. Expected to find the database type after the first ':'. URL: " + url);
    }
    return new TracingConnection(conn, dbType, user, withActiveSpanOnly);
  }

For this line: String user = conn.getMetaData().getUserName(); mysql-connector-java will execute SELECT USER() every time.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
wuyupengwoainicommented, Feb 13, 2019

@pavolloffay please help me to review the pr

1reaction
wuyupengwoainicommented, Jan 17, 2019

Ok, i’ll try to fix it within a few days

Read more comments on GitHub >

github_iconTop Results From Across the Web

"select user()" is executed before every SQL - Stack Overflow
i make my best to find the answer: why "select user()" is executed before every SQLs. i try two way to create dataSource,...
Read more >
JDBC - a short guide - Marco Behler
You can use this guide to learn the basics of JDBC: How to connect to any database and execute SQL queries.
Read more >
30 Application Continuity for Java - Oracle Help Center
You can use both oracle.jdbc.replay. ... The callback is executed every time when both of the following happen: A connection is borrowed from...
Read more >
MySQL programming in Java with JDBC - ZetCode
We will use this database throughout the tutorial. ... The executeQuery() method of the connection object executes the given SQL statement, ...
Read more >
4.22 Troubleshooting Problems Connecting to MySQL
To find out where the socket file is, you can use this command: ... from the client machine, use a SELECT USER() query...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found