내 adapter.xml
<?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>
및 adapter-impl.js
var statement = WL.Server.createSQLStatement("select * from categorie");
function select(statement) {
return WL.Server.invokeSQLStatement({
preparedStatement : statement
});
}
커넥터 .jar
드라이버를 다운로드하여 server/lib
폴더 에서 찾습니다 . 뭐가 잘못 됐는지 모르겠네요 ..
편집 : 아래에서 Worklight 모바일 브라우저 시뮬레이터에서 앱을 실행할 때 콘솔 자바 스크립트 메시지를 게시합니다.
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":[]}}
나는 문제를 해결했다. 나는에 URL의 포트를 편집 .xml
도 내가 기능을 수정, (3306이 아니라 3036입니다) 파일 select(statement)
에 select()
.
수정 된 두 파일 아래.
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"/>
adapter-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: []
});
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다