ADVANCE JAVA LAB
PROGRAM: DEEPIKA (IT 8315)
AIM: DATABASE CONNECTIVITY SOURCE CODE: //CREATE TABLE import [Link].*; public class CreateTable { public static void main(String args[]) { try { [Link]("[Link]"); Connection con = [Link]("jdbc:odbc:studentdsn"); Statement s =[Link](); //String SQLCommand = "create table student(sname varchar(20),srollno number(10),class varchar(10),marks number(10))"; [Link]("create table stu (sname varchar,srollno number,class varchar,marks number)"); [Link]("Table Successfully completed"); [Link](); } catch (Exception e) { [Link](e);} } } //INSERT DATA import [Link].*; import [Link].*;
ADVANCE JAVA LAB
PROGRAM: DEEPIKA (IT 8315)
public class InsertData { public static void main(String args[]) { try { [Link]("[Link]"); Connection con = [Link]("jdbc:odbc:studentdsn"); Statement s =[Link](); PreparedStatement ps=[Link]("insert into stu values(?,?,?,?)"); BufferedReader br = new BufferedReader(new InputStreamReader([Link])); [Link]("Enter Student name : "); [Link](1,[Link]()); [Link]("Enter Student Rollno : "); [Link](2,[Link]([Link]())); [Link]("Enter Class of Student : "); [Link](3,[Link]()); [Link]("Enter Total Marks "); [Link](4,[Link]([Link]())); [Link](); [Link]("Record Successfully Inserted"); [Link](); } catch (Exception e) { [Link](e);} } }
ADVANCE JAVA LAB
PROGRAM: DEEPIKA (IT 8315)
//DISPLAY DATA import [Link].*; import [Link].*; public class DisplayData { public static void main(String args[]) { try { [Link]("[Link]"); Connection con = [Link]("jdbc:odbc:studentdsn"); Statement s =[Link](); ResultSet rs=[Link]("select * from stu"); [Link]("Student name"+"\t"+"roll"+"\t"+"Class"+"\t"+"Total Marks"); while([Link]()) { [Link]([Link](1)+"\t\t"+[Link](2)+"\t" +[Link](3)+"\t"+[Link](4)); } [Link]("Thanks"); [Link](); } catch (Exception e) { [Link](e);} } } OUTPUT:
ADVANCE JAVA LAB
PROGRAM: DEEPIKA (IT 8315)
REMARKS: ________
SIGNATURE:_____________
AIM: WAP TO ADD TWO NUMBERS TAKING ARGUMENTS THROUGH COMMAND LINE. SOURCE CODE: import [Link].*; class addargu
ADVANCE JAVA LAB
PROGRAM: DEEPIKA (IT 8315)
{ public static void main(String [] args)throws IOException { int a=[Link](args[0]); int b=[Link](args[1]); int sum=a+b; [Link]("sum of" +a+" and "+b+" is: "+sum+"."); } } OUTPUT:
REMARKS________ SIGNATURE________ AIM: WAP TO ADD TWO NUMBERS BY USING APPLET. SOURCE CODE: import [Link].*;
ADVANCE JAVA LAB
PROGRAM: DEEPIKA (IT 8315)
import [Link].*; import [Link].*; /* <applet code="applet3" width=500 height=500> </applet> */ public class applet3 extends Applet implements ActionListener { TextField t1,t2,t3; Button b; public void init() { setBackground([Link]); t1=new TextField(6); t2=new TextField(8); t3=new TextField(8); b=new Button("Sum"); add (t1); add (t2); add (t3); add(b); [Link](""); [Link](""); [Link](this); } public void actionPerformed(ActionEvent ae) { int x=0,y=0,z=0; String s1,s2,s3; if([Link]()==b) { try { s1=[Link]();
ADVANCE JAVA LAB
PROGRAM: DEEPIKA (IT 8315)
s2=[Link](); x=[Link](s1); y=[Link](s2); z=x+y; s3=[Link](z); [Link](s3); } catch(Exception e){} } } }
OUTPUT :
ADVANCE JAVA LAB
PROGRAM: DEEPIKA (IT 8315)
REMARKS: ____________
SIGNATURE: __________
ADVANCE JAVA LAB
PROGRAM: DEEPIKA (IT 8315)
AIM: SETTING UP COMMUNICATION BETWEEN CLIENT AND SERVER // A SIMPLE SERVER PROGRAM import [Link].*; import [Link].*; public class SimpleServer { public static void main(String args[]) throws IOException { // Register service on port 3128 ServerSocket s = new ServerSocket(3128); Socket s1=[Link](); // Wait and accept a connection // Get a communication stream associated with the socket OutputStream s1out = [Link](); DataOutputStream dos = new DataOutputStream (s1out); // Send a string! [Link]("U R Reconize by server \n\tHello client "); InputStream in= [Link](); DataInputStream dis = new DataInputStream(in); String st = [Link](); [Link](st);
ADVANCE JAVA LAB
PROGRAM: DEEPIKA (IT 8315)
// Close the connection, but not the server socket [Link](); [Link](); [Link](); } } OUTPUT:
// A SIMPLE CLIENT PROGRAM import [Link].*; import [Link].*;
ADVANCE JAVA LAB
PROGRAM: DEEPIKA (IT 8315)
public class SimpleClient { public static void main(String args[]) throws IOException { // Open your connection to a server, at port 3128 Socket s1 = new Socket("[Link]",3128); // Get an input file handle from the socket and read the input InputStream s1In = [Link](); DataInputStream dis = new DataInputStream(s1In); String st = new String ([Link]()); [Link](st); BufferedReader br = new BufferedReader(new InputStreamReader([Link])); [Link]("Enter data for server"); String line=[Link](); OutputStream out = [Link](); DataOutputStream d= new DataOutputStream (out); // Send a string! [Link](line); // When done, just close the connection and exit [Link](); [Link](); [Link](); } } OUTPUT:
ADVANCE JAVA LAB
PROGRAM: DEEPIKA (IT 8315)
REMARKS: _________
SIGNATURE:___________