Hi...
In the last post we told u that u can make or design the login page according to you as you want.Now we will tell you to make conectivity with MYSQL database....
Steps to do it are as follows..
Step1-make a project in Command prompt as
>webAppCreator -out loginpage com.loginpage
Step2- Now, in eclipse
File > import > Existing project into workspace>Browse loginpage>finish
Step3- add a mysql connector in the project as follow-
loginpage (right click) > build path > Add external archieves > Browse it and add it
Download connector by link-
Step4 - In the login page do coding as for example -
loginpage.java
package com.client;
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class first implements EntryPoint {
/**
* The message displayed to the user when the server cannot be reached or
* returns an error.
*/
private static final String SERVER_ERROR = "An error occurred while "
+ "attempting to contact the server. Please check your network "
+ "connection and try again.";
/**
* Create a remote service proxy to talk to the server-side Greeting service.
*/
GreetingServiceAsync a1 = GWT.create(GreetingService.class);
/**
* This is the entry point method.
*/
RootPanel root;
public void onModuleLoad() {
root=RootPanel.get();
final AbsolutePanel absolutePanel = new AbsolutePanel();
root.add(absolutePanel, 31, 31);
absolutePanel.setSize("383px", "237px");
final TextBox textBox = new TextBox();
absolutePanel.add(textBox, 196, 46);
final PasswordTextBox passwordTextBox = new PasswordTextBox();
absolutePanel.add(passwordTextBox, 196, 97);
Button button = new Button("New button");
button.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
String s1=textBox.getText();
String s2=passwordTextBox.getText();
a1.check(s1,s2, new AsyncCallback<String>() {
@Override
public void onSuccess(String result) {
// TODO Auto-generated method stub
if(result.equals("yes"))
Window.alert("Result ok");
}
@Override
public void onFailure(Throwable caught) {
Window.alert("Result not ok");
}
});
}
});
button.setText("login");
absolutePanel.add(button, 186, 158);
Label lblUsername = new Label("UserName");
absolutePanel.add(lblUsername, 75, 47);
Label lblPassword = new Label("Password");
absolutePanel.add(lblPassword, 75, 98);
Label lblRegisteredUser = new Label("Registered User");
absolutePanel.add(lblRegisteredUser, 122, 10);
Hyperlink hprlnkNewUserClick = new Hyperlink("New User Click Me", false, "newHistoryToken");
hprlnkNewUserClick.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
absolutePanel.clear();
NewUser n=new NewUser();
n.setVisible(true);
}
});
absolutePanel.add(hprlnkNewUserClick, 106, 206);
}
}
Design of loginpage.java
Step 5- Newuser.java
package com.client;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.user.client.ui.PasswordTextBox;
public class NewUser extends Composite {
RootPanel r1;
public NewUser() {
r1=RootPanel.get();
final GreetingServiceAsync a1=GWT.create(GreetingService.class);
AbsolutePanel absolutePanel = new AbsolutePanel();
r1.add(absolutePanel, 48, 10);
absolutePanel.setSize("402px", "280px");
final TextBox textBox = new TextBox();
absolutePanel.add(textBox, 230, 52);
Label lblUsername = new Label("Username");
absolutePanel.add(lblUsername, 69, 53);
Label lblPassword = new Label("Password");
absolutePanel.add(lblPassword, 69, 116);
Label lblConfirmPassword = new Label("Confirm Password");
absolutePanel.add(lblConfirmPassword, 69, 184);
Button button = new Button("New button");
button.setText("Add Me");
absolutePanel.add(button, 137, 222);
final PasswordTextBox passwordTextBox = new PasswordTextBox();
absolutePanel.add(passwordTextBox, 230, 115);
final PasswordTextBox passwordTextBox_1 = new PasswordTextBox();
absolutePanel.add(passwordTextBox_1, 230, 184);
button.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
String s1=textBox.getText();
String s2=passwordTextBox.getText();
String s3=passwordTextBox_1.getText();
if(s2.equals(s3))
{
a1.newuser(s1, s2, new AsyncCallback<String>() {
@Override
public void onSuccess(String result)
{
if(result.equals("yes"))
{
Window.alert("inserted");
}
}
@Override
public void onFailure(Throwable caught) {
Window.alert("Try Again");
}
});
}
else
{
Window.alert("Please Enter Correct Password");
}
}
});
}
}
In the last post we told u that u can make or design the login page according to you as you want.Now we will tell you to make conectivity with MYSQL database....
Steps to do it are as follows..
Step1-make a project in Command prompt as
>webAppCreator -out loginpage com.loginpage
Step2- Now, in eclipse
File > import > Existing project into workspace>Browse loginpage>finish
Step3- add a mysql connector in the project as follow-
loginpage (right click) > build path > Add external archieves > Browse it and add it
Download connector by link-
Step4 - In the login page do coding as for example -
loginpage.java
package com.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyUpEvent;
import com.google.gwt.event.dom.client.KeyUpHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.PasswordTextBox;
import com.google.gwt.user.client.ui.Hyperlink;
/**import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyUpEvent;
import com.google.gwt.event.dom.client.KeyUpHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.PasswordTextBox;
import com.google.gwt.user.client.ui.Hyperlink;
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class first implements EntryPoint {
/**
* The message displayed to the user when the server cannot be reached or
* returns an error.
*/
private static final String SERVER_ERROR = "An error occurred while "
+ "attempting to contact the server. Please check your network "
+ "connection and try again.";
/**
* Create a remote service proxy to talk to the server-side Greeting service.
*/
GreetingServiceAsync a1 = GWT.create(GreetingService.class);
/**
* This is the entry point method.
*/
RootPanel root;
public void onModuleLoad() {
root=RootPanel.get();
final AbsolutePanel absolutePanel = new AbsolutePanel();
root.add(absolutePanel, 31, 31);
absolutePanel.setSize("383px", "237px");
final TextBox textBox = new TextBox();
absolutePanel.add(textBox, 196, 46);
final PasswordTextBox passwordTextBox = new PasswordTextBox();
absolutePanel.add(passwordTextBox, 196, 97);
Button button = new Button("New button");
button.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
String s1=textBox.getText();
String s2=passwordTextBox.getText();
a1.check(s1,s2, new AsyncCallback<String>() {
@Override
public void onSuccess(String result) {
// TODO Auto-generated method stub
if(result.equals("yes"))
Window.alert("Result ok");
}
@Override
public void onFailure(Throwable caught) {
Window.alert("Result not ok");
}
});
}
});
button.setText("login");
absolutePanel.add(button, 186, 158);
Label lblUsername = new Label("UserName");
absolutePanel.add(lblUsername, 75, 47);
Label lblPassword = new Label("Password");
absolutePanel.add(lblPassword, 75, 98);
Label lblRegisteredUser = new Label("Registered User");
absolutePanel.add(lblRegisteredUser, 122, 10);
Hyperlink hprlnkNewUserClick = new Hyperlink("New User Click Me", false, "newHistoryToken");
hprlnkNewUserClick.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
absolutePanel.clear();
NewUser n=new NewUser();
n.setVisible(true);
}
});
absolutePanel.add(hprlnkNewUserClick, 106, 206);
}
}
Design of loginpage.java
Step 5- Newuser.java
package com.client;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.user.client.ui.PasswordTextBox;
public class NewUser extends Composite {
RootPanel r1;
public NewUser() {
r1=RootPanel.get();
final GreetingServiceAsync a1=GWT.create(GreetingService.class);
AbsolutePanel absolutePanel = new AbsolutePanel();
r1.add(absolutePanel, 48, 10);
absolutePanel.setSize("402px", "280px");
final TextBox textBox = new TextBox();
absolutePanel.add(textBox, 230, 52);
Label lblUsername = new Label("Username");
absolutePanel.add(lblUsername, 69, 53);
Label lblPassword = new Label("Password");
absolutePanel.add(lblPassword, 69, 116);
Label lblConfirmPassword = new Label("Confirm Password");
absolutePanel.add(lblConfirmPassword, 69, 184);
Button button = new Button("New button");
button.setText("Add Me");
absolutePanel.add(button, 137, 222);
final PasswordTextBox passwordTextBox = new PasswordTextBox();
absolutePanel.add(passwordTextBox, 230, 115);
final PasswordTextBox passwordTextBox_1 = new PasswordTextBox();
absolutePanel.add(passwordTextBox_1, 230, 184);
button.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
String s1=textBox.getText();
String s2=passwordTextBox.getText();
String s3=passwordTextBox_1.getText();
if(s2.equals(s3))
{
a1.newuser(s1, s2, new AsyncCallback<String>() {
@Override
public void onSuccess(String result)
{
if(result.equals("yes"))
{
Window.alert("inserted");
}
}
@Override
public void onFailure(Throwable caught) {
Window.alert("Try Again");
}
});
}
else
{
Window.alert("Please Enter Correct Password");
}
}
});
}
}
for remaining code see next post
31 May 2011 at 04:45
i get an uncaught exception escaped?? wat to do??
31 May 2011 at 04:49
plz des your problem?
1 February 2012 at 22:32
i have a problem,theres an error saying that
com.mysql.jdbc.DriverNo suitable driver found for jdbc:mysql://localhost:3306/mydb
--what is the solution for that please give me an answer.. I highly appreciate it.Thanks guys.
29 March 2012 at 02:27
just add mysql-connector
Right click on project.Click on Properties > Java Build Path > Libraries >Add Jar
2 June 2012 at 19:08
hi,
I try to connect GWT by mysql and sql but i got a error like "com.google.gwt.user.client.rpc.ServiceDefTarget$NoServiceEntryPointSpecifiedException: Service implementation URL not specified". can y give know what is error and how to fix it?
Thanks.
5 September 2014 at 12:18
pls... share the source. the steps in the tutorial are not working =(
tnx!!!