2013-10-10 65 views
0

我adapter.xmlIBM Worklight SQL适配器 - 无法连接到数据库。无法加载JDBC驱动程序类 'com.mysql.jdbc.Driver'

<?xml version="1.0" encoding="UTF-8"?> 
<wl:adapter name="DbConnect" 

    <displayName>DbConnect</displayName> 
    <description>DbConnect</description> 
    <connectivity> 
     <connectionPolicy xsi:type="sql:SQLConnectionPolicy"> 
      <!-- Example for using a JNDI data source, replace with actual data source name --> 
      <!-- <dataSourceJNDIName>java:/data-source-jndi-name</dataSourceJNDIName> --> 

      <!-- Example for using MySQL connector, do not forget to put the MySQL connector library in the project's lib folder --> 
      <dataSourceDefinition> 
       <driverClass>com.mysql.jdbc.Driver</driverClass> 
       <url>jdbc:mysql://localhost:3036/test</url> 
       <user>root</user> 
       <password>root</password> 
      </dataSourceDefinition> 
     </connectionPolicy> 
     <loadConstraints maxConcurrentConnectionsPerNode="5" /> 
    </connectivity> 

    <!-- Replace this with appropriate procedures --> 
    <procedure name="select"/> 

</wl:adapter> 

和适配器impl.js

var statement = WL.Server.createSQLStatement("select * from categorie"); 
    function select(statement) { 
     return WL.Server.invokeSQLStatement({ 
      preparedStatement : statement 
     }); 
    } 

我下载的连接器.jar驱动程序,并找到它在server/lib文件夹中。我不明白,这可能是错的..

编辑:下面我发布的JavaScript当我运行的应用程序的工作灯移动浏览器模拟器

wlclient init started wlgap.android.js:1481 
before: app init onSuccess wlgap.android.js:1481 
Request [/apps/services/api/Canti_Liturgici/android/query] wlgap.android.js:1481 
after: app init onSuccess wlgap.android.js:1481 
wlclient init success wlgap.android.js:1481 
Failed to load resource: the server responded with a status of 401 (Unauthorized) http://localhost:8080/apps/services/api/Canti_Liturgici/android/query 
Request [/apps/services/api/Canti_Liturgici/android/query] wlgap.android.js:1481 
response [/apps/services/api/Canti_Liturgici/android/query] success: /*-secure- 
{"responseID":"8","errors":["Runtime: org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver'"],"isSuccessful":false,"warnings":[],"info":[]}*/ wlgap.android.js:1481 
Procedure invocation error. Runtime: org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver' wlgap.android.js:1487 
Failure {"status":200,"invocationContext":null,"errorCode":"PROCEDURE_ERROR","errorMsg":"Procedure invocation error. Runtime: org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver'","invocationResult":{"responseID":"8","errors":["Runtime: org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver'"],"isSuccessful":false,"warnings":[],"info":[]}} 
+1

你在哪里找到的连接器?你下载了哪一个?另外 - 尝试删除.jar并将其重新放回,它帮助我一次。 –

+0

@nute我解决了这个问题。我编辑了url的端口(是3306而不是3036),我还在'select()中更正了函数'select(statement)'' –

+0

你能写出这个答案作为答案并将其标记为已答复吗?谢谢。 –

回答

1

我解决了这个问题控制台的消息。我在.xml文件(是3306而不是3036)中编辑了url的端口,我还修正了select()中的函数select(statement)

下面的两个文件更正。

adapter.xml

<displayName>DbConnect</displayName> 
    <description>DbConnect</description> 
    <connectivity> 
     <connectionPolicy xsi:type="sql:SQLConnectionPolicy"> 
      <!-- Example for using a JNDI data source, replace with actual data source name --> 
      <!-- <dataSourceJNDIName>java:/data-source-jndi-name</dataSourceJNDIName> --> 

      <!-- Example for using MySQL connector, do not forget to put the MySQL connector library in the project's lib folder --> 
      <dataSourceDefinition> 
       <driverClass>com.mysql.jdbc.Driver</driverClass> 
       <url>jdbc:mysql://localhost:3306/test</url> 
       <user>root</user> 
       <password>mysql</password> 
      </dataSourceDefinition> 
     </connectionPolicy> 
     <loadConstraints maxConcurrentConnectionsPerNode="5" /> 
    </connectivity> 

    <!-- Replace this with appropriate procedures --> 
    <procedure name="remoteDbSize"/> 

适配器impl.js

var statement = WL.Server.createSQLStatement("SELECT SUM(data_length + index_length) FROM information_schema.TABLES WHERE table_schema = \"test\" GROUP BY table_schema"); 
function remoteDbSize() { 
    return WL.Server.invokeSQLStatement({ 
     preparedStatement : statement, 
     parameters: [] 
    }); 
} 
相关问题