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
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);
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
- loginpage
- Newuser
- GreetingService.java
- GreetingServiceAsync.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
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 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;
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());
}
}
* 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;
}
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) {
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());
}
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-
}
}
Step 8-
- Install MYSQL and start its all services
- mysql cmd>create database mydb;
- cmd > cretae table login(name varchar(20),password varchar(20));
- insert into login values('vishal','myprogram');
- 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