Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

H2 console error: No suitable driver found for 08001/0

Hello Im having problem with viewing my schema in H2 console Database:

Im using spring boot:

spring.datasource.initialize=true
spring.datasource.url=jdbc:h2:~/test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;MV_STORE=FALSE;MVCC=FALSE
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.h2.console.enabled=true

this is my login page:

enter image description here

so what i see inside is standard console view , without my tables and yet my app is working fine.

like image 218
filemonczyk Avatar asked Oct 04 '16 13:10

filemonczyk


People also ask

How do I turn off H2 console?

h2. console. enabled. enabled=false will disable the console, the point is that this is configurable as a property.

What is the default port for H2 database?

However, the default port is 8080, and that port is already being used on my machine. EDIT As mentioned by Atul K below, the h2 web console is available on the configured server.


2 Answers

Usually "Test connection" is working (green line after login form), but connecting does not. This can be caused by handling of headers, which can be caused by filters or security config. For example, I was hit by this twice:

  1. I have same symptoms and problem was caused by usage of logging. Removing dependency helped to get rid of No suitable driver found for 08001/0 message while logging into h2-console:

    <dependency>
        <groupId>org.zalando</groupId>
        <artifactId>logbook-spring-boot-starter</artifactId>
    </dependency>
    

I am not sure, if it is bug of given project, or by wrong usage/config.

  1. Configuring OAuth2 does hit me also. I need to exclude h2-console uri from web and also http security. See some info here. See snippets:

    @Configuration
    @EnableWebSecurity
    @EnableGlobalMethodSecurity(
            securedEnabled = true,
            jsr250Enabled = true,
            prePostEnabled = true
    )
    @RequiredArgsConstructor
    public class SecurityConfig extends WebSecurityConfigurerAdapter {
        @Override
        public void configure(WebSecurity web) {
            web.ignoring().antMatchers("/h2-console/**");
        }
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http
                    // only part of config is shown here...
                    .authorizeRequests()
                    .antMatchers("/",
                            "/error",
                            "/favicon.ico",
                            "/**/*.png",
                            "/**/*.gif",
                            "/**/*.svg",
                            "/**/*.jpg",
                            "/**/*.html",
                            "/**/*.css",
                            "/**/*.js",
                            "/h2-console/**")
                    .permitAll()
                    .antMatchers("/auth/**", "/oauth2/**").permitAll()
                    .anyRequest().authenticated()
                    .and()
                    .oauth2Login();
        }
    }
    
like image 127
Lubo Avatar answered Sep 20 '22 14:09

Lubo


In my case, the problem was that I implemented a custom Filter (see here, here and here) and the custom HttpServletRequestWrapper needs to take care of the H2 console login request which comes with the form data (including Driver Class input) and parse it as parameters:

public class MyHttpServletRequestWrapper extends HttpServletRequestWrapper {

private String body;

public MyHttpServletRequestWrapper(HttpServletRequest request) {
    super(request);
    this.body = IOUtils.toString(request.getReader());
    //...
}

@Override
public Enumeration<String> getParameterNames() {
    if (!parsedParams)
        parseParams();

    List<String> result = Collections.list(super.getParameterNames());
    result.addAll(parameters.keySet());

    return Collections.enumeration(result);
}

private void parseParams() {
    if (!body.isEmpty()) {
        String[] rps = body.split("&");

        for (String rp : rps) {
            String[] kv = rp.split("=");
            try {
                parameters.put(kv[0], kv.length > 1 ? new String[]{URLDecoder.decode(kv[1], "UTF-8")} : new String[]{""});
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }

        parameters.setLocked(true);
        parsedParams = true;
    }
}

@Override
public Map<String, String[]> getParameterMap() {
    if (!parsedParams)
        parseParams();

    Map<String, String[]> s = super.getParameterMap();
    return Stream.concat(parameters.entrySet().stream(), s.entrySet().stream()).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}

@Override
public String getParameter(String name) {
    return parameters.get(name) != null ? parameters.get(name)[0] : super.getParameter(name);
}

@Override
public String[] getParameterValues(String name) {
    String[] s = super.getParameterValues(name);
    return ArrayUtils.addAll(s, parameters.get(name));
}
}
like image 43
y.luis Avatar answered Sep 20 '22 14:09

y.luis