I think I have a trivial problem with a trivial test case, but I am not able to find my error.
Narrative:
In my Eclipse workspace I have set up a Java class in its own project and package that has a few methods to perform some MySQL functions and return a result code. (name: com.adnorm.alib.client.JDBCconnect) It works fine and a separate test class can call it just fine. I have made the MySQL class a .jar file.
In the same workspace, but in a different project, I have defined a trivial GWT class (Login8) to put up a panel with two labels, two textboxes and a button. (username/password and submit). I have an on-click on the button to call my MySQL method to check the username and password. I have the proper import, and Eclipse indicates that it has found the MySQL method on the call statement. There are no source errors flagged by Eclipse. I have added the .jar file of my MySQL class to the Build list for this GWT program. I have not modified the gwt.xml file.
When I RunAs -> Compile GWT Application, I get the following error message:
Compiling module com.mycompany.login8.Login8
Validating newly compiled units
[ERROR] Errors in 'file:/C:/A/MyEclipse8.5/WS1/Login8/src/com/mycompany/login8/client/Login8.java'
[ERROR] Line 42: No source code is available for type com.adnorm.alib.client.JDBCconnect; did you forget to inherit a required module?
Finding entry point classes
[ERROR] Unable to find type 'com.mycompany.login8.client.Login8'
[ERROR] Hint: Previous compiler errors may have made this type unavailable
[ERROR] Hint: Check the inheritance chain from your module; it may not be inheriting a required module or a module may not be adding its source path entries properly
Comment: Why is it looking for the source of JDBCconnect when I just want to reference the .jar? On the Build Path, on the Projects tab, I checked the 'Alib', project. I would have thought this sufficient. (WDISU?? -where did I screw up?) On the Build Path, on the Libraries tab, I included the .jar for JDBCconnect.
Here is the source of the GWT class 'Login8'. It is strictly just a test case and the only lines of code that I added were the import for JDBCconnect and to add the two lines in the OnClick:
package com.mycompany.login8.client;
import com.adnorm.alib.client.JDBCconnect;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;
/**
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class Login8 implements EntryPoint {
public void onModuleLoad() {
RootPanel rootPanel = RootPanel.get();
final FlowPanel flowPanel = new FlowPanel();
rootPanel.add(flowPanel, 6, 48);
flowPanel.setSize("250px", "186px");
final Label lblUsername = new Label("Username:");
flowPanel.add(lblUsername);
final TextBox textUsername = new TextBox();
flowPanel.add(textUsername);
final Label lblPassword = new Label("Password:");
flowPanel.add(lblPassword);
final TextBox textPassword = new TextBox();
flowPanel.add(textPassword);
final Button button = new Button("New button");
button.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
String result_string = JDBCconnect.getUserStatus(textUsername.getText(),textPassword.getText());
Window.alert("Alert:" + result_string);
// put stuff here!!
}
});
button.setText("Submit");
flowPanel.add(button);
}
}
My JDBCconnect code is: (the main method just permits stand-alone testing)
package com.adnorm.alib.client;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class JDBCconnect {
private final static String drivername = "com.mysql.jdbc.Driver";
private final static String driverurl = "jdbc:mysql://192.168.198.21:3306/z1";
private final static String driverusername = "z1";
private final static String driverpassword = "z1";
private final static String USER_VALID = "V";
private final static String USER_NOSUCHUSER = "N";
private final static String USER_INVALIDPASSWD = "X";
private final static String USER_VALIDATIONPENDING = "P";
private final static String USER_ERROR = "X"; // Had error
public static Connection getConnection() throws Exception {
Class.forName(drivername);
Connection conn = DriverManager.getConnection(driverurl, driverusername, driverpassword);
return conn;
}
public static boolean isValidConnection(Connection conn) throws Exception {
if (conn == null) { // null connection object is not valid
return false;
}
if (conn.isClosed()) { // closed connection object is not valid
return false;
}
return true;
}
public static String getUserStatus(String username, String password) {
String return_code = USER_ERROR; // assume there was an error
Connection conn = null;
try {
conn = getConnection();
return_code = USER_NOSUCHUSER;
PreparedStatement s = null;
// System.out.println( "select for username/passwd: " + username + "/" + password);
s = conn.prepareStatement("SELECT user_username, user_password FROM user_master"
+ " WHERE user_username = ? AND user_password = ? " );
s.setString(1,username);
s.setString(2,password);
ResultSet resultSet = s.executeQuery ();
resultSet.last(); // position at last one
int rows = resultSet.getRow(); // set row count
s.close();
// System.out.println("Rows retrieved: " + Integer.toString(rows) );
if (rows == 1) {
return_code = USER_VALID;
}
} catch (Exception e) {
System.out.println(e.getMessage());
return_code = USER_ERROR;
return return_code;
}
return return_code;
}
public static void main(String[] args) {
Connection conn = null;
try {
conn = getConnection();
// System.out.println("conn=" + conn);
// System.out.println("valid connection = " + isValidConnection(conn));
String result_string = getUserStatus("aa","aa");
System.out.println("Result of: " + result_string);
} catch (Exception e) { // handle the exception
System.out.println(e.getMessage());
e.printStackTrace();
System.exit(1);
} finally { // release database resources
try {
conn.close();
} catch (Exception e) {
}
}
}
}