

Google App
EngineにWebアプリケーションを配備しました。配備自体は成功したのですが、サイトにアクセスすると下記のようなエラーが出てしまいます。JDK7を使用、JDBCはojdbc7.jarとmysql-
connector-java-5.1.34-bin.jarを試しましたが、いずれも同じエラーが発生してしまいます。  
DBはGoogle Cloud SQLにMySQLのデータベースを配備してあります。  
どなたかお分かりになる方いらっしゃいましたら、アドバイスお願いします。よろしくお願いいたします。

> oracle.jdbc.driver.OracleDriver registerMBeans: Error while registering
> Oracle JDBC Diagnosability MBean.  
>  java.lang.NoClassDefFoundError: java.lang.management.ManagementFactory is a
> restricted class. Please see the Google App Engine developer's guide for
> more details.  
>  at
> >com.google.apphosting.runtime.security.shared.stub.java.lang.management.ManagementFactory.(ManagementFactory.java)  
>  at oracle.jdbc.driver.OracleDriver.registerMBeans(OracleDriver.java:327)  
>  at oracle.jdbc.driver.OracleDriver$1.run(OracleDriver.java:209)  
>  at
> >com.google.apphosting.runtime.security.shared.intercept.java.security.AccessController_.doPrivileged(AccessController_.java:34)  
>  at oracle.jdbc.driver.OracleDriver.(OracleDriver.java:205)  
>  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)  
>  at
> >sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)  
>  at
> >sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)  
>  at java.lang.reflect.Constructor.newInstance(Constructor.java:526)  
>  at java.lang.Class.newInstance(Class.java:370)  
>  at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:373)  
>  at java.util.ServiceLoader$1.next(ServiceLoader.java:445)  
>  at java.sql.DriverManager$2.run(DriverManager.java:510)  
>  at java.sql.DriverManager$2.run(DriverManager.java:490)  
>  at java.security.AccessController.doPrivileged(Native Method)  
>  at java.sql.DriverManager.loadInitialDrivers(DriverManager.java:490)  
>  at java.sql.DriverManager.(DriverManager.java:100)  
>  at com.mysql.jdbc.Driver.(Driver.java:63)  
>  at java.lang.Class.forName0(Native Method)  
>  at java.lang.Class.forName(Class.java:266)  
>  at
> >com.google.apphosting.runtime.security.shared.intercept.java.lang.Class_.loadClassOrStub(Class_.java:536)  
>  at
> >com.google.apphosting.runtime.security.shared.intercept.java.lang.Class_.access$100(Class_.java:42)  
>  at
> >com.google.apphosting.runtime.security.shared.intercept.java.lang.Class_$2.run(Class_.java:128)  
>  at
> >com.google.apphosting.runtime.security.shared.intercept.java.lang.Class_$2.run(Class_.java:123)  
>  at java.security.AccessController.doPrivileged(Native Method)  
>  at
> >com.google.apphosting.runtime.security.shared.intercept.java.lang.Class_.forName(Class_.java:123)  
>  at utility.DAO.connect(DAO.java:31)  
>  at anki_note.AnkiNote.doPost(AnkiNote.java:76)  
>  at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)  
>  at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)  
>  at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)  
>  at
> org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)  
>  at
> >com.google.apphosting.utils.servlet.ParseBlobUploadFilter.doFilter(ParseBlobUploadFilter.java:125)  
>  at
> >org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)  
>  at
> >com.google.apphosting.runtime.jetty.SaveSessionFilter.doFilter(SaveSessionFilter.java:35)  
>  at
> >org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)  
>  at
> >com.google.apphosting.utils.servlet.JdbcMySqlConnectionCleanupFilter.doFilter(JdbcMySqlConnectionCleanupFilter.java:60)  
>  at
> >org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)  
>  at
> >com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)  
>  at
> >org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)  
>  at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)  
>  at
> org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)  
>  at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)  
>  at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)  
>  at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)  
>  at
> >com.google.apphosting.runtime.jetty.AppVersionHandlerMap.handle(AppVersionHandlerMap.java:254)  
>  at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)  
>  at org.mortbay.jetty.Server.handle(Server.java:326)  
>  at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)  
>  at
> >org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)  
>  at
> >com.google.apphosting.runtime.jetty.RpcRequestParser.parseAvailable(RpcRequestParser.java:76)  
>  at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)  
>  at
> >com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:146)  
>  at
> >com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run(JavaRuntime.java:527)  
>  at
> >com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:437)  
>  at
> >com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:444)  
>  at com.google.tracing.CurrentContext.runInContext(CurrentContext.java:220)  
>  at
> >com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:308)  
>  at
> >com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:300)  
>  at
> >com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:441)  
>  at
> >com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:251)  
>  at java.lang.Thread.run(Thread.java:724)

Here is my source code to connect to my database.

[code]

    public static final String DB_URL = "jdbc:google:mysql://caramel-clover-813:myapplication?user=root";
    public static final String DB_USER = "user";
    public static final String DB_PASSWORD = "xxxx";
    public boolean connect()
    {   
        boolean is_connect = false;
    
        try
        {
            Class.forName("com.mysql.jdbc.GoogleDriver");
    
            this.conn = DriverManager.getConnection(DB_URL, DB_USER, DB_PASSWORD);
            this.stmt = this.conn.createStatement();
    
            is_connect = true;
        }
        catch (ClassNotFoundException e)
        {
            e.printStackTrace();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return is_connect;
    }
    
[/code]


CC BY-SA 3.0
2015-03-04T05:18:58.203
7416
2015-03-05T03:15:09.073
8673
question
java mysql google-app-engine jdbc
Google App Engine:oracle.jdbc.driver.OracleDriver registerMBeans: Error while registering Oracle JDBC Diagnosability MBean


MySQLを利用されているのに、OracleDBのJDBCドライバを使っているようですが、MySQL接続にはmysqlのJDBCドライバ"のみ"を指定してください。


CC BY-SA 3.0
2015-03-05T01:12:53.087
7456
2015-03-05T01:12:53.087
5778
7416
answer


[Using Google Cloud SQL - Java — Google Cloud
Platform](https://cloud.google.com/appengine/docs/java/cloud-
sql/#Java_Connect_to_your_database)から抜粋して回答いたします。

まず、`appengine-web.xml`に以下のように`<use-google-connector-j>true</use-google-
connector-j>`の記述がされているか確認してください。

[code]

    <?xml version="1.0" encoding="utf-8"?>
    <appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
      ...
      <use-google-connector-j>true</use-google-connector-j>
    </appengine-web-app>
    
[/code]

次に、以下のようにして`Connection`を取得できることを確認してください。

[code]

    Class.forName("com.mysql.jdbc.GoogleDriver");
    Connection conn = DriverManager.getConnection("jdbc:google:mysql://your-project-id:your-instance-name/guestbook", "username", "password");
    
[/code]

`DriverManager.getConnection`に渡す`url`の形式は

[code]

    jdbc:google:mysql://<プロジェクトID>:<インスタンス名>/<データベース名>
    
[/code]

であることに注意してください。`DriverManager.getConnection`に引数でユーザー名やパスワードを渡す場合は、`url`に`user`のパラメーターは不要です。


CC BY-SA 3.0
2015-03-05T03:15:09.073
7462
2015-03-05T03:15:09.073
3160
7416
answer