Hi..
Step 6-In the left hand side click on tree of the project and src will be extract...
In src >com.client> there are 4 files
  1. loginpage
  2. Newuser
  3. GreetingService.java
  4. GreetingServiceAsync.java
GreetingService.java

package com.client;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
/**
 * The client side stub for the RPC service.
 */
@RemoteServiceRelativePath("greet")
public interface GreetingService extends RemoteService {
  String check(String name,String password);
  String newuser(String name,String password);
}

Code for GreetingServiceAsync.java


 
interface GreetingServiceAsync {void check(String name,String password, AsyncCallback<String> callback);void newuser(String name,String password,AsyncCallback<String> callback);
com.client;
package
import
/**
* The async counterpart of
*/
<code>GreetingService</code>.
public
void check(String name,String password, AsyncCallback<String> callback);
void newuser(String name,String password,AsyncCallback<String> callback);
}
interface GreetingServiceAsync {
com.google.gwt.user.client.rpc.AsyncCallback;
Step 7-

Open src >  Com.Server  >


Greeting ServiceImpl.java

package com.server;

import java.net.ConnectException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import com.client.GreetingService;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
/**
 * The server side implementation of the RPC service.
 */
@SuppressWarnings("serial")
public class GreetingServiceImpl extends RemoteServiceServlet implements
    GreetingService {


 Connection con=null;
 Statement st=null;


 ResultSet rs=null;


 String url="jdbc:mysql://localhost:3306/mydb";


 public void call()
 {
  try
  {
   Class.forName("com.mysql.jdbc.Driver");
  }
  catch(ClassNotFoundException e)
  {
   System.out.print(e.getMessage());
  }
  try
  {
   con=DriverManager.getConnection(url, "root", "");
   st=con.createStatement();
  }
  catch(SQLException e)
  {
   System.out.println(e.getMessage());
  }
 }
@Override
public String check(String s1, String s2) {
 // TODO Auto-generated method stub
 String ss="no";
 call();


 try
 {

   rs = st.executeQuery("select * from login where name='" + s1 + "' and password='" + s2+"'" );
  
   if(rs.next())
   {
    ss="yes";
    System.out.println(rs.getString(0));
    System.out.println(rs.getString(1));
   }


 }
 catch(SQLException e)
 {
  System.out.println(e.getMessage());

 }


 return ss;
}
@Override
public String newuser(String name, String password) {
 String ss = "no";
 call();


 try
 {
  boolean ss1;
   ss1 = st.execute("insert into login values('" + name+"','"+ password +"')");
  
   if(ss1)
   {
   
   
    ss="yes";
   }



 }
 catch(SQLException e)
 {
  System.out.println(e.getMessage());

 }
 return ss;


}
}
Step 8-

  1. Install MYSQL and start its all services
  2. mysql cmd>create database mydb;
  3. cmd > cretae table login(name varchar(20),password varchar(20));
  4. insert into login values('vishal','myprogram');
  5. insert into login values('sonal','helloworld');
Hence now the program is complete and u can us it for database connectivity.
Thank you,
SONAL GARG
VISHAL DIXIT

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;
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;
/**
 * 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 5Newuser.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

Hi..
This will help you to make your gwt workable....
Essential software you should have are-
  1. Eclipse             download link-http://www.eclipse.org/downloads/
  2. GWT               download link-http://fileforum.betanews.com/detail/Google-Web-Toolkit-GWT-for-Windows/1147889979/1
  3. MYSQL           download link-
  4. Step 1 -
                      cmd > gwt 1.7.1 >webAppCreator -out login com.login
                      Note- Here we are creating the project named "login"



>close cmd
Step 2 -     
  •  Open Eclipse
  • Open File menu
  • Choose import >Existing project into workspace>Select a root directory(Browse in GWT 1.7.1)>finish


 After Finish login project will show at left side of screen.

Step 3-  Right Click on login project  > run as >Run Configuration >java Application >login >Run


After that login page will run
as...........................

Now You can design your own login page as you want you can also take help our next post...
Thank You...
Good Day....




counter

free counters

Total Pageviews

Recent Posts

Contributors

Followers

Powered by Blogger.