SQLContainer

Hi everbody!

I’m trying to connect to MySQL, but every time the same exception:

HTTP Status 500 - com.vaadin.server.ServiceException: java.lang.RuntimeException: Specified JDBC Driver: com.mysql.jdbc.Driver - initialization failed.

I also checked the base connection (its good).
And also try to change database (no effect).
And of course add *.jar files to class_path.

Code:

@SuppressWarnings("serial")
@Theme("simple")
public class SimpleUI extends UI {
    @WebServlet(value = "/*", asyncSupported = true)
    @VaadinServletConfiguration(productionMode = false, ui = SimpleUI.class)
    public static class Servlet extends VaadinServlet {
    }

    @Override
    protected void init(VaadinRequest request) {

        //DbTable screen = new DbTable();
    
        try {
            SimpleJDBCConnectionPool pool = new SimpleJDBCConnectionPool("com.mysql.jdbc.Driver","jdbc:mysql://localhost:3306/test", "user", "");
            //screen.polulate("student", pool);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } 

        //setContent(screen);
    }

}

PS. Most of this code are from Learning Vaadin 7 book. There was SimpleJDBCConnectionPool without Simple, but it doesnt matter, because I checked both ways.

PPS. Someone, give me please
simple example with
1) how to connect to DB on localhost and VPS server 2) how to add data to container 3) how to represent data from container to simple table or combobox.
I spend too much time for this and it still not works ((.

Hello there,

Please check the following -

  • Check if your DB is up.
  • Check the credentials you are using to access the DB. I see that you are trying to connect to test DB with UserName user and password emptyString somehow I feel that this is not right.
  • Once this is done check the url you are using to access the DB(port)
  • Cross check your class path - check if driver is part of WEB-INF/lib
  • Krishna

Thanks for answer!

“Check if your DB is up.”

  • “check the url you are using to access the DB(port)”
  • I can connect to DB through MySQLWorkbench. I can create another databse and tables. I think it works, yes?

“Cross check your class path - check if driver is part of WEB-INF/lib”

  • I connected driver to class_path (Properties - Java Build Path). I can see it in Java Resources/Libraries. But Web Content/WEB-INF/lib is empty.

“Check the credentials you are using to access the DB. I see that you are trying to connect to test DB with UserName user and password emptyString somehow I feel that this is not right.”

  • Credentials? What does it mean? UserName user and password emptyString are initial (primary) for MySQL. And I can use it to connect using MySQLWorkbench (or another tools like dbForge Studio for MySQL)

Can you please post the complete stacktrace of the error? Also, Can you please check if MySql driver is available during runtime?

-Krishna

"Can you please check if MySql driver is available during runtime? "

  • Excuse me, how can I check it?

“stacktrace”

  • See attached
    13594.png

I just checked connection to MySQL through tools and found one strange thing: I can use any user login…
And I can connect in and see tables inside

Before I had Mysql5.6, but trying to connect with J-Connector 5.1.30.
I removed this version and instaled 5.1.73.
And the same result…

My last source:

SimpleJDBCConnectionPool pool = new SimpleJDBCConnectionPool("com.mysql.jdbc.Driver","jdbc:mysql://localhost:3307/", "root", "password"); I also try this:

SimpleJDBCConnectionPool pool = new SimpleJDBCConnectionPool("com.mysql.jdbc.Driver","jdbc:mysql://localhost:3307/mysql", "root", "password", 2, 5); and this:

JDBCConnectionPool pool = new SimpleJDBCConnectionPool("com.mysql.jdbc.Driver","jdbc:mysql://localhost:3307/mysql", "root", "password", 2, 5);

PS. I connected ot DB through
Data Source Explorer in Eclipse
. Its working - I can see DB and schemas in footer
window.
And you asked about WEB-INF/lib. Its still empty.

Hello There,

The root cause shows that you have a class not found execution. Which means you don’t have your MySql Driver in the classpath during runtime. So please add the same WEB-INF/lib to resolve this issue.

Also, just FYI, the default username for MySql is root and password is empty string.

Hope this solves your issue.

-Krishna

How to add? Just copy from Libraries? I cant - “Cannot paste the clipboard contents into the selected elements”
I changed MySQL login and pass.

just copy the mysql driver jar to WEB-INF/lib that is all you have to do.

I assume that you are using eclipse, and trying to copy the jar from a zip or an archieve file. So first this is to either to extract that file in to your local system or copy paste the jar to the local system after which copy the extracted version of jar to the specified folder.

I got it!

Thank you 1000 times!
And for future: if I want to add some *.jar to project I have to have 2 copies: in Libraries and in WEB-INF/lib?

If you have it in WEB-INF/lib, automatically that gets added to the class path and runtime. So its not mandatory to have it in seperate library.

Krishna, if you have some of extra time, could you give me some on a paying basis lessons through skype or another messanger by typing.
My final purpose is to create simple webapp with auth. Users have defferent roles and access to data (db table). Also I have to add TouchKit, but there I need only auth and do some INSERT to db.

Hello There,

I’m Sorry to dissapoint you, I am
not
an authroized trainer for Vaadin
nor
an employee of
Vaadin Ltd
. I’m Just arround here to provide what ever help I can for others and simultaneouly learn some thing new. If you are willing to Pay, I would strongly suggest you should take up Vaadin
Training
or take
Commercial support
from Vaadin.

Having said that I would be around in vaadin forums and on stackoverflow with Pseduo name
Patton
, or can mail me on
Linkedln
if in case of any concerns please feel free to tag me and I would be there to help you out on what ever I can.

  • Krishna.