【问题标题】:Could not connect Smartgwt application with mysql database remote server无法将 Smartgwt 应用程序与 mysql 数据库远程服务器连接
【发布时间】:2021-04-13 16:04:11
【问题描述】:

我一直在尝试将 smartgwt 客户端应用程序连接到 MySQL 服务器。
我已经创建了服务器端实现“MySQLConection” 和客户端同步和异步接口。
我在入口点类中创建了一个 RPC 对象,但每次我尝试启动它时都会得到

Line 13: No source code is available for type java.lang.ClassNotFoundException; did you forget to inherit a required module?
Line 13: No source code is available for type java.sql.SQLException; did you forget to inherit a required module?

在第 13 行我有

ArrayList onLoad() throws ClassNotFoundException, SQLException, IOException;

我已经在 *.gwt.xml 文件中添加了标签并且 还包括 jar 文件

这是我的连接代码

public Connection MySQLConnection() {
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            
            e.printStackTrace();
            return null;
        }

        Connection connection = null;

        try {
            connection = (Connection) DriverManager.getConnection(url, user, pass);

        } catch (SQLException e) {
            
            e.printStackTrace();
            return null;
        }
    
        return connection;
    }

这是我的 *gwt.xml 代码

<module rename-to='Abc'>
    <inherits name="com.google.gwt.user.User" />
    <inherits name="com.google.gwt.user.theme.standard.Standard" />
    <inherits name="com.smartgwt.SmartGwt" />
    <entry-point class="com.xyz.client.Abc" />


    <!-- Inherit the default GWT style sheet. You can change -->
    <!-- the theme of your GWT application by uncommenting -->
    <!-- any one of the following lines. -->
    <!-- <inherits name='com.google.gwt.user.theme.standard.Standard'/> -->
    <!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
    <!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/> -->

    <!-- Other module inherits -->
    <!-- <inherits name="com.smartgwt.SmartGwt"/> -->
    <inherits name="com.smartgwt.SmartGwtNoTheme" />
    <inherits name="com.smartclient.theme.enterpriseblue.EnterpriseBlue" />
    <inherits name="com.smartclient.theme.enterpriseblue.EnterpriseBlueResources" />

    <servlet class="com.xyz.server.MySQLConnection" path="/MySQLConnection" />
    <source path='client' />
    <source path='shared' />

    

</module>

我在入口类中调用连接如下

rpc = (DBConnectionAsync) GWT.create(DBConnection.class);

【问题讨论】:

    标签: mysql smartgwt


    【解决方案1】:

    您遇到此问题是因为您必须在 client 文件夹中包含的类中编写一些访问 ClassNotFoundException, SQLException, IOException 的代码。

    此文件夹中的任何类都无法访问每个 Java 类。

    您的服务器端逻辑应该写在一个包含在 server 文件夹中的类中。

    要了解 GWT 的项目结构,请查看以下链接:

    https://developers.google.com/web-toolkit/doc/1.6/DevGuideOrganizingProjects#DevGuideDirectoriesPackageConventions

    要了解为什么不能使用 client 包中的每个类,请查看以下链接:

    GWT - did you forget to inherit a required module?

    【讨论】:

    • RAS 我已经在服务器文件夹中编写了该逻辑..但是异步接口需要声明我想从客户端代码执行的方法(在服务器逻辑上)..问题是我的方法需要抛出异常,所以我不得不提到它void fetchNames(String Query,AsyncCallback&lt;ArrayList&lt;Bean&gt;&gt; callback) throws SQLException, ClassNotFoundException, IOException;
    • 是的,但即使您导入任何这些类,GWT 也会抱怨。你必须找到一个替代方案。
    猜你喜欢
    • 1970-01-01
    • 2012-10-09
    • 1970-01-01
    • 2016-06-22
    • 2014-03-04
    • 1970-01-01
    • 2017-10-17
    • 2017-06-26
    • 2011-01-26
    相关资源
    最近更新 更多