简体   繁体   中英

Using ORMLite with Google App Engine - Cloud SQL

I'm playing around with GAE Cloud SQL and trying to use it in combination with ORMLite.

Currently I'm making the connection to the database like this:

DriverManager.registerDriver(new AppEngineDriver());
connection = DriverManager.getConnection("jdbc:google:rdbms://" + instanceName + "/" + databaseName);

But ORMLite uses a ConnectionSource , something like this:

ConnectionSource connectionSource = new JdbcConnectionSource(databaseUrl);

// instantiate the dao
Dao<SomeClass, String> accountDao =
            DaoManager.createDao(connectionSource, SomeClass.class);

Now I'm not sure that this will work on GAE in production if I set the connectionSource to:

dbc:google:rdbms://" + instanceName + "/" + databaseName

Has anyone used ORMLite in combination with GAE Cloud SQL ... or is there any other way to connect ORMLite and GAE?

Yes, it is possible, but you have to pass the connection you manually created before:

JdbcSingleConnectionSource connectionSource = new JdbcSingleConnectionSource("jdbc:mysql://127.0.0.1/yourdb?user=root", connection);
connectionSource.initialize();

The URL doesn't really matter as long as you create the connection correctly

I know this question is ages old, but i couldnt find the answer anywhere else so I figured it could still help some people

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM