1. #1
    Sencha User
    Join Date
    Mar 2008
    Posts
    150
    Vote Rating
    1
    phamtranquocviet is on a distinguished road

      0  

    Default Weird Error

    Weird Error


    Hi,

    I have a class called CadaoDb.java in com.cadao.server package. In my entry point class, platform.java, I import com.cadao.CadaoDb. No matter what I try, it repeatedly complains this error:

    [ERROR] Errors in 'file:/C:/Documents%20and%20Settings/Administrator/My%20Documents/My%20Data/cd/gxt/platform/src/com/cadao/client/platform.java'
    [ERROR] Line 5: The import com.cadao.server.CadaoDb cannot be resolved



    Here are the files:
    1- Entry Point: platform.java

    Code:
    package com.cadao.client;
    import java.sql.Connection;
    import com.cadao.server.CadaoDb;
    import com.google.gwt.core.client.EntryPoint;
    
    public class platform implements EntryPoint
    {
    	public void onModuleLoad()
    	{
    		CadaoDb cadaoDb = new CadaoDb();
    		Connection connection = cadaoDb.getConnection();
    		System.out.println(connection.toString());
    	}
    }
    2- Config file: platform.gwt.xml
    Code:
    <module>
          <inherits name='com.google.gwt.user.User'/>
          <inherits name='com.google.gwt.user.theme.standard.Standard'/>
          <entry-point class='com.cadao.client.platform'/>
          <stylesheet src='platform.css' />
    </module>
    3- Attached is the snapshot of my file hierarchy in zip format (sorry, it's too big).

    I thought I got passed this kind of errors, but obviously not. Please help. Thanks a bunch.
    Attached Files

  2. #2
    Ext GWT Premium Member gslender's Avatar
    Join Date
    Mar 2008
    Location
    Brisbane, Australia
    Posts
    1,572
    Vote Rating
    3
    gslender is on a distinguished road

      0  

    Default


    1st - java.sql.Connection won't be able to be imported into a GWT client app and won't compile even if you fix this

    2nd - com.cadao.server.CadaoDb is in the server package - only classes in the client package are visible to the GWT compiler.

    These are GWT issues, not GXT.

  3. #3
    Sencha User
    Join Date
    Mar 2008
    Posts
    150
    Vote Rating
    1
    phamtranquocviet is on a distinguished road

      0  

    Default


    gslender,

    For security reason, I need two separate applications. A new person needs to register an account. This is the first application. A registered person uses a second application to access stuffs I do not want non-registered people to hack into. Both will need to talk to DB. How do I factor out the RPC codes that contact DB and reference in both applications? From your explanations, it looks like I need to repeat RPC codes in both apps. Any hints? Thanks.

  4. #4
    Ext GWT Premium Member gslender's Avatar
    Join Date
    Mar 2008
    Location
    Brisbane, Australia
    Posts
    1,572
    Vote Rating
    3
    gslender is on a distinguished road

      0  

    Default


    yup... simply create another GWT source path/package and add this to your gwt.xml

    Code:
      	<source path="data"/>
      	<source path="client"/>
    com.cadao.client <-- your gwt client side UI classes
    com.cadao.data <-- your gwt/server pojo classes
    com.cadao.server <-- your server side servlet classes

  5. #5
    Sencha User
    Join Date
    Mar 2008
    Posts
    150
    Vote Rating
    1
    phamtranquocviet is on a distinguished road

      0  

    Default


    gslender,

    Are you saying that I need to repeat the RPC codes in both apps, or are you saying that I can factor out and use source tag to include them. I did some research on how to use source tag, it looks like factoring is not possible.

    http://code.google.com/p/google-web-...thsHandlingFAQ

    Thanks.

  6. #6
    Ext GWT Premium Member gslender's Avatar
    Join Date
    Mar 2008
    Location
    Brisbane, Australia
    Posts
    1,572
    Vote Rating
    3
    gslender is on a distinguished road

      0  

    Default


    you'll need to explain more clearly what you are trying to do.

    your original issue was GWT compiling and getting an error regarding a class that isn't in the source path of the compiler - com.cadao.server.CadaoDb

    the comment regarding two applications/security is irrelevent and confusing

  7. #7
    Sencha User
    Join Date
    Mar 2008
    Posts
    150
    Vote Rating
    1
    phamtranquocviet is on a distinguished road

      0  

    Default


    gslender,

    I fixed the package scope issue by dropping the database classes directly into my com.cadao.server package that has my RPC implementation. That seems to work, but I now get an exception relating to java.sql.Connection as you predicted. I searched the forum but could not find any hint on what connection package I should import. What kind of connection package should I import? Or how to fix this code so that I can talk to the MYSQL database? Thanks.

    [ERROR] Line 11: No source code is available for type java.sql.SQLException; did you forget to inherit a required module?

    Here is the code:
    Code:
    package com.cadao.server;
    
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    
    public abstract class Db
    {
    	private String driver = "com.mysql.jdbc.Driver";
    	
    	/**
    	 *  Constructor 
    	 */
    	public Db()
    	{ }
    	
    	protected abstract String getUrl();
    	protected abstract String getDb();
    	protected abstract String getUser();
    	protected abstract String getPassword();
    	
    	public final Connection getConnection()
    	{
    		String url = getUrl();
    		String db = getDb();
    		String user = getUser();
    		String password = getPassword();
    		Connection connection = null;
    		try
    		{
    			Class.forName(driver).newInstance();
    			connection = DriverManager.getConnection(url + db, user, password);
    		}
    		catch(Exception e)
    		{
    			System.err.println("Mysql Connection Error: ");
    			e.printStackTrace();
    		}
    		return connection;
    	}
    
    	protected static int getResultSetSize(ResultSet resultSet)
    	{
    		int size = -1;
    		try
    		{
    			resultSet.last();
    			size = resultSet.getRow();
    			resultSet.beforeFirst();
    		}
    		catch(SQLException e)
    		{ return size; }
    		return size;
    	}
    }

  8. #8
    Ext GWT Premium Member gslender's Avatar
    Join Date
    Mar 2008
    Location
    Brisbane, Australia
    Posts
    1,572
    Vote Rating
    3
    gslender is on a distinguished road

      0  

    Default


    I think you need to think a little more high level about what you are trying to do.

    GWT is a client (browser) application that results in Java code being compiled to Javascript. There is no connection to your server unless you explicitly make one - ie there is no way to SQL connect to the DB in GWT using Java objects - ie you can't just "talk to the MYSQL database"

    RPC, XML and JSON are common methods to transfer data between the client and web server using HTTP (this is a GWT concept and nothing to do with ExtGWT) - you need to wrap transfer and marshalling code around this to actually perform the concept of querying and updating data. What you do at the server side (ie Servlet container) is up to you, and again GWT doesn't anwser this problem or provide a solution.

    I'd encourage you read more about GWT or perhaps consider buying a book on the subject as clearly this fundamental concept needs to be fully understood before you even design the application UI - which is what ExtGWT offers.

  9. #9
    Sencha User
    Join Date
    Mar 2008
    Posts
    150
    Vote Rating
    1
    phamtranquocviet is on a distinguished road

      0  

    Default


    gslender,

    Making explicit RPC to the server is what I am doing. Here is what I am trying to do and how:

    - I need to check if the entered SSN already exists by calling function isDuplicate(...) function, which is an RPC implementation and resides on the server side (*Impl.java) in a package called com.cadao.server of my application. isDuplicate(...) needs to talk to database to check username and password. I, therefore, dropped the database classes such as Db.java and Cadao.java into the com.cadao.server package of my application (a different application, not platform application that we discussed in the thread) to make the connection. So, it's all on the server side. Sorry for not being clear.

    - I hardcoded isDuplicate(....) and made sure that isDuplicate(...) function already worked.
    Thanks gslender.

  10. #10
    Ext GWT Premium Member gslender's Avatar
    Join Date
    Mar 2008
    Location
    Brisbane, Australia
    Posts
    1,572
    Vote Rating
    3
    gslender is on a distinguished road

      0  

    Default


    My advice still stands - read more about GWT and RPC.

    ie - you can't transfer ANY kind of object you like via RPC. The Java objects need to be able to survive GWT JRE library emulation and there is only a limited type of Java objects that can... eg POJO's are fine. A java.sql.Connection object is not.

Thread Participants: 2