DB SERVER
==========
import java.io.*;
import java.sql.*;
import java.net.*;
public class DBServer
{
static Connection con;
static Statement st1,st2;
static ResultSet rs1;
static ResultSetMetaData rsmd;
static String[] rec=new String[10];
static ServerSocket ss=null;
static Socket s=null;
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:irk","system","bvrice");
st1=con.createStatement();
st2=con.createStatement();
System.out.println("Done");
}
catch(Exception e)
{
System.out.println("Error establishing connection"+e);
}
String output=" ",qry=" ";
try
{
ss=new ServerSocket(1090);
System.out.println("Server");
s=ss.accept();
BufferedReader in=new BufferedReader(new InputStreamReader(s.getInputStream()));
PrintWriter out=new PrintWriter(s.getOutputStream(),true);
out.println("welcome to DBServer");
while(true)
{
int choice=Integer.parseInt(in.readLine());
String usr=null,pass=null;
int c=0;
switch(choice)
{
case 1:usr=in.readLine();
pass=in.readLine();
c=st1.executeUpdate("insert into userinfo values('"+usr+"','"+pass+"')");
if(c==1) out.println("Date inserted succcessfully");
break;
case 2: usr=in.readLine();
pass=in.readLine();
System.out.println("username="+usr+"password="+pass);
rs1=st1.executeQuery("select * from userinfo where userid='"+usr+"'");
while(rs1.next())
{
c=st1.executeUpdate("Update userinfo set password='"+pass+"' where userid ='"+usr+"'");
}
if(c==1) out.println("password updated for the given username");
else
out.println("update not possible");
break;
case 3:usr=in.readLine();
rs1=st1.executeQuery("select * from userinfo where userid='"+usr+"'");
rs1.next();
System.out.println(rs1.getString(1)+" "+rs1.getString(2));
out.println(rs1.getString(2));
break;
case 4:usr=in.readLine();
c=st1.executeUpdate("delete userinfo where userid='"+usr+"'");
if(c==1) out.println("userinformation for the following userid"+usr+"is deleted");
break;
default:break;
}
}
}
catch(Exception ie)
{}
}
}