GWT: database connectivity with my sql
Login form : login.java
package com.client;
import com.client.GreetingService;
import com.client.GreetingServiceAsync;
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.Cookies;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.PasswordTextBox;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.TabBar;
import com.google.gwt.event.logical.shared.SelectionHandler;
import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.Image;
public class login implements EntryPoint {
boolean flag=true;
String username;
String s5;
Image image;
AbsolutePanel absolutePanel;
AbsolutePanel absolutePanel_1;
RootPanel rootPanel;
Image image_2;
TextBox username1 ;
PasswordTextBox password1;
Button signin;
TabBar tabBar;
boolean flag1=false;
Label lblCheckAgainYour;
Hyperlink forget;
public void onModuleLoad() {
final GreetingServiceAsync a1 = GWT.create(GreetingService.class);
rootPanel = RootPanel.get();
rootPanel.setSize("1500", "1000");
rootPanel.setStyleName("h1");
absolutePanel = new AbsolutePanel();
absolutePanel.setStyleName("gwt-abs");
rootPanel.add(absolutePanel, 200, 10);
absolutePanel.setSize("1000px", "593px");
image = new Image("66.jpg");
absolutePanel.add(image, 0, 0);
image.setSize("1000px", "71px");
absolutePanel_1 = new AbsolutePanel();
absolutePanel.add(absolutePanel_1, 460, 120);
absolutePanel_1.setSize("432px", "379px");
image_2 = new Image("13.jpg");
image_2.setStyleName("gwt-Label-new");
absolutePanel_1.add(image_2, 10, 10);
image_2.setSize("422px", "360px");
username1= new TextBox();
absolutePanel_1.add(username1, 232, 108);
password1 = new PasswordTextBox();
absolutePanel_1.add(password1, 232, 166);
Label label = new Label("Email Id");
label.setStyleName("gwt-Label-new");
absolutePanel_1.add(label, 70, 108);
Label label_1 = new Label("Password");
label_1.setStyleName("gwt-Label-new");
absolutePanel_1.add(label_1, 70, 167);
signin = new Button("New button");
signin.setText("Welcome to Enggheads");
signin.setStyleName("gwt-Button1");
absolutePanel_1.add(signin, 50, 266);
signin.setSize("274px", "34px");
tabBar = new TabBar();
tabBar.addTab(" Sign In");
tabBar.addTab(" Sign Up");
tabBar.setStyleName("gwt-TabBar1");
absolutePanel_1.add(tabBar, 20, 23);
tabBar.setSize("134px", "27px");
forget = new Hyperlink("Forget Your Password", false, "newHistoryToken");
forget.setStyleName("gwt-Hyperlink1");
absolutePanel_1.add(forget, 119, 314);
forget.setSize("205px", "21px");
lblCheckAgainYour = new Label("Check again your id and password");
lblCheckAgainYour.setStyleName("gwt-Label-new");
absolutePanel_1.add(lblCheckAgainYour, 93, 221);
lblCheckAgainYour.setSize("286px", "27px");
lblCheckAgainYour.setVisible(false);
Image image_1 = new Image("66.jpg");
absolutePanel.add(image_1, 0, 527);
image_1.setSize("1000px", "56px");
Label label_2 = new Label("New label");
absolutePanel.add(label_2, 153, 149);
Label label_3 = new Label("New label");
absolutePanel.add(label_3, 84, 166);
tabBar.addSelectionHandler(new SelectionHandler<Integer>() {
public void onSelection(SelectionEvent<Integer> event) {
if(tabBar.getSelectedTab()==1)
{
signup s1=new signup();
absolutePanel_1.clear();
s1.onModuleLoad();
}
}
});
forget.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
forget f1=new forget();
f1.onModuleLoad();
}
});
signin.addClickHandler(new ClickHandler(){
public void onClick(ClickEvent e)
{
try
{
username=username1.getText();
s5=password1.getText();
if(flag1==false )
{
a1.sign(username, s5,new AsyncCallback<String>() {
@Override
public void onSuccess(String arg0) {
// TODO Auto-generated method stub
System.out.println(arg0);
if(arg0.equals("YES"))
{
flag1=true;
//Window.alert("incorrect username and password");
}
if(arg0.equals("no"))
{
//Window.alert("kcdj");
lblCheckAgainYour.setVisible(true);
password1.setFocus(true);
//flag=true;
}
}
@Override
public void onFailure(Throwable arg0) {
// TODO Auto-generated method stub
//signin.setText("asd");
}
});
}
a1.fullname(username,new AsyncCallback<String>(){
public void onSuccess(String arg0) {
if(flag1==true){
Cookies.setCookie("fullname", arg0);
String fullname=Cookies.getCookie("fullname");
System.out.println(fullname);
welcome w=new welcome();
absolutePanel.clear();
w.onModuleLoad();
}
}
public void onFailure(Throwable arg0) {
}
});
}
catch(Exception e1)
{
System.out.println(e1.toString());
}
}
});
}
}
GreetingService
package com.client;
import java.util.ArrayList;
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 {
public String sign(String s4,String s5);
public String fullname(String username);
}
GreetingService Asynchronous
package com.client;
import java.util.ArrayList;
import com.google.gwt.user.client.rpc.AsyncCallback;
/**
* The async counterpart of <code>GreetingService</code>.
*/
public interface GreetingServiceAsync {
void sign(String s4,String s5, AsyncCallback<String> callback);
void fullname(String username,AsyncCallback<String> callback);
}
Server file
package com.server;
import com.client.GreetingService;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import javax.servlet.http.HttpSession;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.*;
import java.util.*;
import java.io.*;
import com.sun.mail.smtp.*;
import javax.mail.PasswordAuthentication;
import javax.mail.Authenticator;
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;
String from;
boolean flag=true;
MimeMessage message;
private String smtpServer;
public void connect()
{
try
{
Class.forName("com.mysql.jdbc.Driver");
System.out.println("1");
}
catch(ClassNotFoundException e)
{
System.out.println(e.getMessage());
}
try{
System.out.println("2");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/login","root","root");
System.out.println("3");
st = con.createStatement();
}
catch(SQLException e)
{
System.out.println(e.toString());
}
}
public String sign(String s4,String s5)
{
connect();
System.out.println(s4);
System.out.println(s5);
String ss1="no";
ResultSet rs = null;
try
{
rs = st.executeQuery("select * from sub where username='" + s4 + "' and password='" + s5+"'" );
System.out.println("hello");
if(rs.next())
{
ss1="YES";
}
}
catch(SQLException e)
{
System.out.println(e.toString());
}
System.out.println(ss1);
return ss1;
}
@Override
public String change(String query) {
connect();
String s=null;
int i=0;
try
{
i=st.executeUpdate(query);
System.out.println("hello"+i);
}
catch(Exception e)
{
System.out.println(e.toString());
}
return "helloyes";
}
public String fullname(String username)
{
connect();
ResultSet rs = null;
String s1=null;
try
{
rs = st.executeQuery("select fullname from user where username='" + username +"'" );
if(rs.next())
{
s1= rs.getString("fullname");
}
}
catch(Exception e)
{
System.out.println(e.toString());
}
return s1;
}
}
}
Login form : login.java
package com.client;
import com.client.GreetingService;
import com.client.GreetingServiceAsync;
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.Cookies;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.PasswordTextBox;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.TabBar;
import com.google.gwt.event.logical.shared.SelectionHandler;
import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.Image;
public class login implements EntryPoint {
boolean flag=true;
String username;
String s5;
Image image;
AbsolutePanel absolutePanel;
AbsolutePanel absolutePanel_1;
RootPanel rootPanel;
Image image_2;
TextBox username1 ;
PasswordTextBox password1;
Button signin;
TabBar tabBar;
boolean flag1=false;
Label lblCheckAgainYour;
Hyperlink forget;
public void onModuleLoad() {
final GreetingServiceAsync a1 = GWT.create(GreetingService.class);
rootPanel = RootPanel.get();
rootPanel.setSize("1500", "1000");
rootPanel.setStyleName("h1");
absolutePanel = new AbsolutePanel();
absolutePanel.setStyleName("gwt-abs");
rootPanel.add(absolutePanel, 200, 10);
absolutePanel.setSize("1000px", "593px");
image = new Image("66.jpg");
absolutePanel.add(image, 0, 0);
image.setSize("1000px", "71px");
absolutePanel_1 = new AbsolutePanel();
absolutePanel.add(absolutePanel_1, 460, 120);
absolutePanel_1.setSize("432px", "379px");
image_2 = new Image("13.jpg");
image_2.setStyleName("gwt-Label-new");
absolutePanel_1.add(image_2, 10, 10);
image_2.setSize("422px", "360px");
username1= new TextBox();
absolutePanel_1.add(username1, 232, 108);
password1 = new PasswordTextBox();
absolutePanel_1.add(password1, 232, 166);
Label label = new Label("Email Id");
label.setStyleName("gwt-Label-new");
absolutePanel_1.add(label, 70, 108);
Label label_1 = new Label("Password");
label_1.setStyleName("gwt-Label-new");
absolutePanel_1.add(label_1, 70, 167);
signin = new Button("New button");
signin.setText("Welcome to Enggheads");
signin.setStyleName("gwt-Button1");
absolutePanel_1.add(signin, 50, 266);
signin.setSize("274px", "34px");
tabBar = new TabBar();
tabBar.addTab(" Sign In");
tabBar.addTab(" Sign Up");
tabBar.setStyleName("gwt-TabBar1");
absolutePanel_1.add(tabBar, 20, 23);
tabBar.setSize("134px", "27px");
forget = new Hyperlink("Forget Your Password", false, "newHistoryToken");
forget.setStyleName("gwt-Hyperlink1");
absolutePanel_1.add(forget, 119, 314);
forget.setSize("205px", "21px");
lblCheckAgainYour = new Label("Check again your id and password");
lblCheckAgainYour.setStyleName("gwt-Label-new");
absolutePanel_1.add(lblCheckAgainYour, 93, 221);
lblCheckAgainYour.setSize("286px", "27px");
lblCheckAgainYour.setVisible(false);
Image image_1 = new Image("66.jpg");
absolutePanel.add(image_1, 0, 527);
image_1.setSize("1000px", "56px");
Label label_2 = new Label("New label");
absolutePanel.add(label_2, 153, 149);
Label label_3 = new Label("New label");
absolutePanel.add(label_3, 84, 166);
tabBar.addSelectionHandler(new SelectionHandler<Integer>() {
public void onSelection(SelectionEvent<Integer> event) {
if(tabBar.getSelectedTab()==1)
{
signup s1=new signup();
absolutePanel_1.clear();
s1.onModuleLoad();
}
}
});
forget.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
forget f1=new forget();
f1.onModuleLoad();
}
});
signin.addClickHandler(new ClickHandler(){
public void onClick(ClickEvent e)
{
try
{
username=username1.getText();
s5=password1.getText();
if(flag1==false )
{
a1.sign(username, s5,new AsyncCallback<String>() {
@Override
public void onSuccess(String arg0) {
// TODO Auto-generated method stub
System.out.println(arg0);
if(arg0.equals("YES"))
{
flag1=true;
//Window.alert("incorrect username and password");
}
if(arg0.equals("no"))
{
//Window.alert("kcdj");
lblCheckAgainYour.setVisible(true);
password1.setFocus(true);
//flag=true;
}
}
@Override
public void onFailure(Throwable arg0) {
// TODO Auto-generated method stub
//signin.setText("asd");
}
});
}
a1.fullname(username,new AsyncCallback<String>(){
public void onSuccess(String arg0) {
if(flag1==true){
Cookies.setCookie("fullname", arg0);
String fullname=Cookies.getCookie("fullname");
System.out.println(fullname);
welcome w=new welcome();
absolutePanel.clear();
w.onModuleLoad();
}
}
public void onFailure(Throwable arg0) {
}
});
}
catch(Exception e1)
{
System.out.println(e1.toString());
}
}
});
}
}
GreetingService
package com.client;
import java.util.ArrayList;
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 {
public String sign(String s4,String s5);
public String fullname(String username);
}
GreetingService Asynchronous
package com.client;
import java.util.ArrayList;
import com.google.gwt.user.client.rpc.AsyncCallback;
/**
* The async counterpart of <code>GreetingService</code>.
*/
public interface GreetingServiceAsync {
void sign(String s4,String s5, AsyncCallback<String> callback);
void fullname(String username,AsyncCallback<String> callback);
}
Server file
package com.server;
import com.client.GreetingService;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import javax.servlet.http.HttpSession;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.*;
import java.util.*;
import java.io.*;
import com.sun.mail.smtp.*;
import javax.mail.PasswordAuthentication;
import javax.mail.Authenticator;
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;
String from;
boolean flag=true;
MimeMessage message;
private String smtpServer;
public void connect()
{
try
{
Class.forName("com.mysql.jdbc.Driver");
System.out.println("1");
}
catch(ClassNotFoundException e)
{
System.out.println(e.getMessage());
}
try{
System.out.println("2");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/login","root","root");
System.out.println("3");
st = con.createStatement();
}
catch(SQLException e)
{
System.out.println(e.toString());
}
}
public String sign(String s4,String s5)
{
connect();
System.out.println(s4);
System.out.println(s5);
String ss1="no";
ResultSet rs = null;
try
{
rs = st.executeQuery("select * from sub where username='" + s4 + "' and password='" + s5+"'" );
System.out.println("hello");
if(rs.next())
{
ss1="YES";
}
}
catch(SQLException e)
{
System.out.println(e.toString());
}
System.out.println(ss1);
return ss1;
}
@Override
public String change(String query) {
connect();
String s=null;
int i=0;
try
{
i=st.executeUpdate(query);
System.out.println("hello"+i);
}
catch(Exception e)
{
System.out.println(e.toString());
}
return "helloyes";
}
public String fullname(String username)
{
connect();
ResultSet rs = null;
String s1=null;
try
{
rs = st.executeQuery("select fullname from user where username='" + username +"'" );
if(rs.next())
{
s1= rs.getString("fullname");
}
}
catch(Exception e)
{
System.out.println(e.toString());
}
return s1;
}
}
}
No comments:
Post a Comment