Вы находитесь на странице: 1из 45

Aim: Program implementing all necessary tags Source code:

<html> <head> <title>Welcome</title> </head> <body bgcolor="white" text ="times new roman" scroll="yes" > <img src="D:\wt record\Example58\logo.bmp" width="100" height= "100" align="right"> </img> <br/> <font size ="16" face="times new roman" color="black"> <center><h1> DRKIST </h1></center> <br/> <font size="6" face="times new roman" color="black" > <marquee ><i> Welcome to DRK Institute </marquee></font> <h2> <i>welcome to DRK institute </h2> </font> <br><br><br><br><br><br><br><br> <br> <font size="3" face="times new roman" color="blue" > <p align= "right"><a href="c:/Example58/details.html"> Details </a> </font> <hr> <h6 align ="bottom" > All Rights Reserved </h6> </body> </html>

Aim: Program to display the static web pages (Home, Registration, Catalog, Cart) Source code: 1.Home:
<html> <head> <title> Welcome </title> </head> <body bgcolor="white" text ="times new roman" scroll="yes" > <img src="D:\wt record\Example58\logo.bmp" width="100" height= "100" align="right"> </img> <br/> <font size ="16" face="times new roman" color="black"> <center><h1> DRKIST </h1></center> <br/> <font size="6" face="times new roman" color="black" > <marquee ><i> Welcome to DRK Institute </marquee></font> <h2> <i>welcome to DRK institute </h2> </font> <br><br><br><br><br><br><br><br> <br> <font size="3" face="times new roman" color="blue" > <p align= "right"><a href="c:/Example58/details.html"> Details </a> </font> <hr> <h6 align ="bottom" > All Rights Reserved </h6> </body> </html>

2.Registration:
<html> <head> <title> login page </title> </head> <body bgcolor="white"> <form name="f1" method="post"> <p align="right">username<input type="text" name="t1" maxlength="20"> password<input type="password" name="t2" maxlength="20"><input type="submit" value="login"></form> <img src="logo.bmp" width="100" height= "100" align="right"> </img><br><br> <u><h1 align="center">LOGIN</h1></u><br>

<h3><u>About:</u></h3> <font size="2" face="verdana" color="black"> <i><b>DRK Institute of Science and Technology</b> is an Engineering college established in 2004.The college is affliated to <b>Jawaharlal Nehru Tecnological University Hyderabad</b>.It has been successfully training the students in the field of Engineering and Technology and provided the state many successful engineers. <br>To know more about the college and courses offered in the college please <u>sign up</u> to the site.If you are already a member please <u>sign in</u> to know the details.</i> </font> <br> <H3><u>SIGN UP</u></h3> <form name ="f2" method="post"> First name<input type="text" name="t1" maxlength="20"><br> <br> last name<input type="text" name="t3" maxlength="20"><br> <br> Email id<input type="text" name="t4" maxlength="20"><br> <br> User name<input type="text" name="t1" maxlength="20"><br> <br> password<input type="password" name="t2"maxlength="20"><br> <br> Re-typepassword<input type="password" name="t2"maxlength="20"> <br> <br> <input type="submit" value="submit"> <input type="reset"> </form> <hr></hr> <font size="1" face="verdana" color="black"> All rights reserved</font> </body> </html>

3.Catalog:
<html> <head> <title>catalogue</title> </head> <body bgcolor="white"> <table border="1" cellspacing="1" cellpadding="1"> <tr> <td><img src="logo1.jpg" width="100" height= "100" align="right"></img></td> <td>author:xxx <br>bname:xxxx<br> publisher:xxx<br></td> <td>cost</td>

<td><input type="submit" value="add to cart"></td> </tr> <tr> <td><img src="logo2.jpg" width="100" height= "100" align="right"></img></td> <td>author:xxx <br>bname:xxxx<br> publisher:xxx<br></td> <td>cost</td> <td><input type="submit" value="add to cart"></td> </tr> <tr> <td><img src="logo3.jpg" width="100" height= "100" align="right"></img></td> <td>author:xxx <br>bname:xxxx<br> publisher:xxx<br></td> <td>cost</td> <td><input type="submit" value="add to cart"></td> </tr> </body> </html>

4.Cart:
<html> <head> <title>cart</title> </head> <body bgcolor="white"> <table border="1" cellspacing="1" cellpadding="1"> <tr> <th>Book name</th> <th>price</th> <th>Quantity</th> <th>Amount</th> </tr> <td>bname:xxxx</td> <td>12</td> <td>x</td> <td>amount</td> </tr> </tr> <td>bname:xxxx</td> <td>12</td> <td>x</td> <td>amount</td> </tr> </table> </body> </html>

Aim: Program to implement Cascade Style Sheets (CSS) (Internal, External, Inline) Source code: External CSS:
<html> <head> <title>css example</title> <link rel="stylesheet" href="extcss.css"> </head> <body> <h3>welcome to css</h3> <a href="welcome1.html">home page</a> </body> </html>

CSS:
a:link{color:blue}; a:active{color:green}; a:visited{color:black}; a:hover{color:red};

Internal:
<html> <head> <title>welcome</title> </head> <style type="text/css"> body{background:white;color:red} a:link{color:green}; a:active{color:pink}; a:visit{color:black}; a:hover{color:blue}; </style> <body> <h3>working with style sheets</h3> <a href="ex.html">home page</a> </body> </html>

Inline:
<html> <head> <title>css</title> <style type="text/css"> body{background-image:logo1.bmp} .xlink{cursor:crosshair} .hlink{cursor:help} <div style="position:relative;top:10;background-color:blue;z-index:1;">layer 1</div> </style> </head> <body> <b> <a href="welcome.html"class="xlink">cross link</a> <br> <a href="help.html"class="hlink">help link</a> </b> <b class="headline">this is headline</b> </body> </html>

Aim: Program to display Class TimeTable Source code:


<html> <body><center> <b><h1><font size="+3"> TIME TABLE </h1></b><br> <table border="5" cellspacing="2" cellpadding="5"height="400" width="700"> <th> <font size="+2">DAY </th><th><font size="+2">1 </th><th><font size="+2">2</th><th><font size="+2">3</th><th><font size="+2">4</th><th rowspan="6"><font size="+2">L<br>U<br>N<br>C<br>H</th><th><font size="+2">5</th><th><font size="+2">6</th><th><font size="+2">7</th> <tr><td>MONDAY</td><td>MC</td><td>ACA</td><td>SPM</td><td>DWDM</td><td>NP </td><td>WT</td><td>WT</td></tr> <tr><td>TUESDAY</td><td>ACA</td><td colspan="3"> WT LAB</td><td>ACA</td><td>DWDM</td><td>SPM</td></tr> <tr><td>WEDNESDAY</td><td>ACA</td><td colspan="3"> NP LAB</td><td>DWDM</td><td>SPM</td><td>WT </td></tr> <tr><td>THRUSDAY</td><td>MC</td><td>ACA</td><td>SPM</td><td>DWDM</td><td> NP</td><td>WT</td><td>WT</td></tr> <tr><td>FRIDAY</td><td>WT</td><td>DWDM</td><td>SPM</td><td>ACA</td><td>NP</ td><td>MC</td><td>WT</td></tr> </center> </body> </html>

Aim: Program to display Validation of the Registration Page Source code:


<html> <head> <title>login validatn</title> <script language="javascript"> function validate_username() { s=f1.t1.value; d=s.length; if(f1.t1.value==""||d<6) { window.alert("please enter the username with atleast 6 characters"); f1.t1.focus(); f1.t1.value=""; } } function validate_password() { s=f1.t2.value; d=s.length; if(f1.t2.value!=f1.t3.value||d<6) { window.alert("Password not matched or please enter the password with atleast 6 characters"); f1.t2.focus(); } } function validate_emailId() { s=f1.t4.value; d1=s.indexOf("@"); d2=s.indexOf("."); p=d2-d1; if(p<=1||d1==0||d1==-1) { window.alert("Please enter a valid EmailId"); f1.t4.focus(); f1.t4.value=""; } } function validate_Phno() { s=f1.t5.value; d=s.length; if(d<10||isNaN(s))

{ window.alert("Please enter a valid Phone No"); f1.t5.focus(); f1.t5.value=""; } } </script> </head> <body bgcolor="white"> <form name="f1" method="post"> <center><u>REGISTERATION PAGE</u></center><br><br> <center> <table cellspacing="15" cellpadding="5"> <tr> <td>Username</td><td><input type="text" name="t1" onblur="validate_username()"></td> </tr> <tr> <td>Password</td><td><input type="password" name="t2"></td></tr> <tr><td>ConfirmPassword</td><td><input type="password" name="t3"onblur="validate_password()"></td></tr> <tr><td>Email Id</td><td><input type="text" name="t4"onblur="validate_emailId()"></td></tr> <tr><td>Phone no.</td><td><input type="text" name="t5"onblur="validate_Phno()"></td> </tr> <tr><td>Gender</td><td><input type="radio" name="t6">Male<br> <input type="radio" name="t6">Female </td> </tr> <tr><td>Date of Birth</td> <td>Date:&nbsp;<select name="date"> &nbsp; <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option>5</option> <option>6</option> <option>7</option> <option>8</option> <option>9</option> <option>10</option> <option>11</option> <option>12</option> <option>13</option> <option>14</option>

<option>15</option> <option>16</option> <option>17</option> <option>18</option> <option>19</option> <option>20</option> <option>21</option> <option>22</option> <option>23</option> <option>24</option> <option>25</option> <option>26</option> <option>27</option> <option>28</option> <option>29</option> <option>30</option> </select> Month:&nbsp<select name="month" > &nbsp; <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option>5</option> <option>6</option> <option>7</option> <option>8</option> <option>9</option> <option>10</option> <option>11</option> <option>12</option> </select> Year:&nbsp<select name="Year" > <option>1990</option> <option>1991</option> <option>1992</option> <option>1993</option> <option>1994</option> <option>1995</option> <option>1996</option> <option>1997</option> </select> </td> </tr> <tr> <td>Languages</td>

<td><input type="checkbox" name="c1" value="English">English<br> <input type="checkbox" name="c1">Hindi<br> <input type="checkbox" name="c1">telugu<br> </td> </tr> <tr> <td>Address</td><td><textarea rows="5" cols="18"></textarea></td> </tr> </table><br> <input type="button" value="submit"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset"> </center> </body> </html>

Aim: Program to Create Calculator application with basic functionalities. Source code:
<html> <head> <title>CALCUALTOR</title> <script language="Javascript"> txtdata=""; function Cal(value) { txtdata=txtdata+value; document.f1.t1.value=txtdata; } </script> </head> <body> <form name="f1"> <table border=10 bgcolor="silver" bordercolor="silver"> <tr> <th>CALCULATOR</th> </tr> <tr> <td> <input type="text" maxlength="10" size="25" name="t1"> </td> </tr> <tr> <td> <input type="button" value=" 1 " onclick="Cal('1')"> <input type="button" value=" 2 " onclick="Cal('2')"> <input type="button" value=" 3 " onclick="Cal('3')"> <input type="button" value=" + " onclick="Cal('+')"> </td> </tr> <tr> <td> <input type="button" value=" 4 " onclick="Cal('4')"> <input type="button" value=" 5 " onclick="Cal('5')"> <input type="button" value=" 6 " onclick="Cal('6')"> <input type="button" value=" - " onclick="Cal('-')"> </td> </tr> <tr> <td> <input type="button" value=" 7 " onclick="Cal('7')"> <input type="button" value=" 8 " onclick="Cal('8')"> <input type="button" value=" 9 " onclick="Cal('9')">

<input type="button" value=" </td> </tr> <tr> <td> <input type="button" value=" <input type="button" value=" <input type="button" value=" <input type="button" value=" </td> </tr> </table> </form> </body> </html>

* " onclick="Cal('*')">

0 C = /

" onclick="Cal('0')"> "onclick="txtdata='';f1.t1.value=''";> "; onclick="f1.t1.value=eval(txtdata)"> " onclick="Cal('/')">

Aim: Program to implement Sorting technique Source code:


<html> <head> <title> sorting </title> <script language="javascript"> var a=new Array(5); var i; document.writeln("length=" +a.length); for(i=0;i<a.length;i++) a[i]=parseInt(window.prompt("enter a number","0")); for(i=0;i<a.length;i++) { for(j=i+1;j<a.length;j++) { if(a[i]>a[j]) { var temp=a[i]; a[i]=a[j]; a[j]=temp; } } } document.writeln("ascending"); for(i=0;i<a.length;i++) document.writeln(a[i] +" "); document.writeln("descending"); for(i=a.length-1;i>=0;i--) document.writeln(a[i] +" "); </script> </head> <body> </body> </html>

Aim: Program to implement Searching for a Pivot element Source code:


<html> <head> <title>search pivot element</title> <script language="javascript"> document.write("<br>enter the no of number to be entered into array<br>"); var b =window.prompt("enter the no of number to be entered into array"); var c =parseInt(b); document.write(c); var a = new Array(c); document.write("<br>enter the numbers into the array<br>"); for(i=0;i<a.length;i++) { a[i]=window.prompt("enter values into array"); document.write(a[i]);document.write("&nbsp&nbsp&nbsp"); } document.write("<br>number to be searched is :"); var p = window.prompt("enter the number to be searched"); var n = parseInt(p); document.write(n); var q=0; for(i=0;i<a.length;i++) { if(a[i]==n) q=1; } if(q==1) document.write("<br>number found <br>"); else document.write("<br>number not found<br>"); </script> </head> </html>

Aim: Program to Reverse a given number Source code:


<html> <head> <title>reversse of number</title> <script language="javascript"> var i=window.prompt("enter the number"); var a=parseInt(i); document.write("<br>enter the number to be reversed<br>"); document.write(a); var c=parseInt(0); while(a>0) { var b=parseInt(a%10); var c=parseInt(c*10+b); var a=parseInt(a/10); } document.write("<br>the number after reversing is<br>"); document.write(c); </script> </head> </html>

Aim: Program to check whether a given number is a palindrome or not. Source code:
<html> <head> <title> palindrome</title> </head> <body> <script language="javascript"> var s1=window.prompt("enter a number","0"); var a=parseInt(s1); var b=parseInt(s1); var r=0; var rev=0; while (a>0) { r=parseInt(a%10); rev=parseInt((rev*10)+r); a=parseInt(a/10); } document.writeln("original="+b); document.writeln("rev="+rev); if(b==rev) { document.writeln("given number is palindrome"); } else { document.writeln(" given number is not a palindrome"); } </script> </body> </html>

Aim: Program to display the Employee details using XML file. Source code:
HTML File: <html> <head> <title>records</title> <script language="javascript"> function First() { p.recordset.moveFirst; } function Next() { p.recordset.moveNext; if(p.recordset.EOF) { window.alert("last record"); p.recordset.moveLast; } } function Previous() { p.recordset.movePrevious; if(p.recordset.BOF) { window.alert("first record"); p.recordset.moveFirst; } } function Last() { p.recordset.moveLast; } </script> </head> <body> <form name="f1"> <xml id="p" src ="emp1.xml"></xml> <u>Employee Details</u> <table> <tr> <td>employee number</td><td><input type="text" name="t1" datasrc="#p" datafld="eno"></td></tr><br> <tr><td>employee name</td><td><input type="text" name="t2" datasrc="#p" datafld="ename"></td></tr><br>

<tr><td>employee salary</td><td><input type="text" name="t3" datasrc="#p" datafld="esal"></td></tr><br> <tr><td>department</td><td><input type="text" name="t4" datasrc="#p" datafld="dept"></td></tr><br> </table> <input type="button" value="First" onclick="First()"> <input type="button" value="Next" onclick="Next()"> <input type="button" value="Previous" onclick="Previous()"> <input type="button" value="Last" onclick="Last()"> </form> </body> </html> XML File: <EMP> <employee> <eno>1041</eno> <ename>ads</ename> <esal>34500</esal> <dept>cse</dept> </employee> <employee> <eno>1042</eno> <ename>absc</ename> <esal>32445</esal> <dept>it</dept> </employee> <employee> <eno>1043</eno> <ename>agc</ename> <esal>30345</esal> <dept>cse</dept> </employee> </EMP>

Aim: Program to implement Internal DTDs. Source code:


<?xml version="1.0"?> <!DOCTYPE EMP[ <!ELEMENT employee (eno,ename,esal,dept)> <!ELEMENT eno (#PCDATA)> <!ELEMENT ename (#PCDATA)> <!ELEMENT esal (#PCDATA)> <!ELEMENT dept (#PCDATA)> ]> <EMP> <employee> <eno>1041</eno> <ename>ads</ename> <esal>34500</esal> <dept>cse</dept> </employee> <employee> <eno>1042</eno> <ename>absc</ename> <esal>32445</esal> <dept>it</dept> </employee> <employee> <eno>1043</eno> <ename>agc</ename> <esal>30345</esal> <dept>cse</dept> </employee> <employee> <eno>1044</eno> <ename>xasc</ename> <esal>32345</esal> <dept>eee</dept> </employee> <employee> <eno>1045</eno> <ename>cxc</ename> <esal>30045</esal> <dept>ece</dept> </employee> <employee> <eno>1046</eno> <ename>xxx</ename>

<esal>30005</esal> <dept>cse</dept> </employee> <employee> <eno>1047</eno> <ename>yxsc</ename> <esal>3000</esal> <dept>cse</dept> </employee> <employee> <eno>1048</eno> <ename>aExample</ename> <esal>30000</esal> <dept>cse</dept> </employee> <employee> <eno>1049</eno> <ename>sai</ename> <esal>325</esal> <dept>cse</dept> </employee> <employee> <eno>1050</eno> <ename>sudheer</ename> <esal>4000</esal> <dept>cse</dept> </employee> </EMP>

Aim: Program to implement External DTDs. Source code:


<!DOCTYPE employee SYSTEM "D:\wt record\Example58\empdetail.dtd"> <employee> <details> <name gender="male">name:Example</name> <address>address:hyderabad</address> <phno> <resi>111111</resi> <mobile>9700103789</mobile> </phno> <dept>cse</dept> <email>Example@gmail.com</email> </details> </employee> DTD File: <!ELEMENT employee (details)+> <!ELEMENT details (name,address,dob,doj,phno,dept,email*)> <!ELEMENT name (#PCDATA)> <!ATTLIST name gender (male|female) #REQUIRED> <!ELEMENT address (#PCDATA)> <!ELEMENT dob (#PCDATA)> <!ELEMENT doj (#PCDATA)> <!ELEMENT phno (resi,mobile)> <!ELEMENT resi (#PCDATA)> <!ELEMENT mobile (#PCDATA)> <!ELEMENT dept (#PCDATA)> <!ELEMENT email (#PCDATA)>

Aim: Program to display the number of root elements and to display the nodes. Source code:
Display the number of root elements: <html> <head> <title>DOM PARSER</title> <xml id="p" src="emp1.xml"></xml> <script language="javascript"> doc=p; if(doc.parseError!=0) { window.alert(doc.parseError.reason); } else { var rootE1=doc.documentElement; var childlist=rootE1.childNodes; document.writeln("<b>"+"the number of nodes for the root element in the xml document="+childlist.length+"</b>"+"<br>"); document.writeln("<b>"+"name of node is="+rootE1.lastChild.nodeName+"</b>"+"<br>"); } </script> </head> </html> Display the nodes. <html> <head> <title>DOM PARSER</title> <xml id="p" src="emp1.xml"></xml> <script language="javascript"> doc=p; var emplist; if(doc.parseError!=0) { window.alert(doc.parseError.reason); } else { emplist=doc.getElementsByTagName("employee"); for(var i=0;i<emplist.length;i++) { document.writeln(emplist.item(i).firstChild.firstChild.nodeValue+"<br>");

} } </script> </head> </html>

JDBC PROGRAMS Aim: Java Program to Create a table in SQL database. Source code:
import java.sql.*; public class tabemp { public static void main(String r[])throws Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:Example","scott","tiger"); Statement st=con.createStatement(); st.executeUpdate("create table emp(eno number,ename varchar2(20),esal number,dept varchar2(10))"); System.out.println("Table is created"); } }

Aim: Write a Java Program to Insert values into SQL database. Source code:
import java.sql.*; public class insemp { public static void main(String r[])throws Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:Example","scott","tiger"); Statement st=con.createStatement(); int i=st.executeUpdate("insert into emp values(561,'ram',4500,'it')"); if(i>0) System.out.println("1 row is inserted"); else System.out.println("error"); } }

Aim: Java Program to Update values in SQL database. Source code:


import java.sql.*; import java.lang.*; public class updaemp { public static void main(String r[])throws Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:Example","scott","tiger"); Statement st=con.createStatement(); int i=st.executeUpdate("update emp set esal=esal+5000"); if(i>0) System.out.println("rows updated"+i); else System.out.println("error"); } }

Aim: Java Program to Delete a row in SQL database. Source code:


import java.sql.*; public class delemp { public static void main(String r[])throws Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:Example","scott","tiger"); Statement st=con.createStatement(); int i=st.executeUpdate("delete from emp where esal<9000"); } }

Aim: Java Program to Select all rows of a table in SQL database. Source code:
import java.sql.*; public class selemp { public static void main(String r[])throws Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:Example","scott","tiger"); Statement st=con.createStatement(); ResultSet rs=st.executeQuery("select * from emp"); while(rs.next()) System.out.println(rs.getInt(1)+"\t"+rs.getString(2)+"\t"+rs.getInt(3)+"\t"+rs.getString(4)); } }

Aim: Java Program to Insert values from Keyboard. Source code:


import java.sql.*; import java.io.*; import java.lang.*; public class keybrdemp { public static void main(String r[ ])throws Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:Example","scott","tiger"); Statement st=con.createStatement(); InputStreamReader is=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(is); int eno1=Integer.parseInt(br.readLine()); String ename1=br.readLine(); int esal1=Integer.parseInt(br.readLine()); String dept1=br.readLine(); int i=st.executeUpdate("insert into emp values("+eno1+",'"+ename1+"',"+esal1+",'"+dept1+"')"); if(i>0) System.out.println("1 row is inserted"); else System.out.println("error"); } }

Aim: Java Program to Update values taking input from Keyboard. Source code:
import java.sql.*; import java.io.*; public class kbupdemp { public static void main(String r[])throws Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:Example","scott","tiger"); Statement st=con.createStatement(); InputStreamReader is=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(is); System.out.println("enter the amount to be updated"); int sal=Integer.parseInt(br.readLine()); int i=st.executeUpdate("update emp set esal=esal+"+sal+""); if(i>0) System.out.println("rows updated"+i); else System.out.println("error"); } }

Aim: Java Program to Delete values taking input from Keyboard. Source code:
import java.sql.*; import java.io.*; public class kbdelemp { public static void main(String r[])throws Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:Example","scott","tiger"); Statement st=con.createStatement(); InputStreamReader is=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(is); System.out.println("enter the amount range that are to be deleted"); int amt=Integer.parseInt(br.readLine()); int i=st.executeUpdate("delete from emp where esal<"+amt+""); if(i>0) System.out.println("rows deleted="+i); else System.out.println("error"); } }

Aim: Java Program to Insert values into table through Command Prompt. Source code:
import java.sql.*; import java.io.*; import java.lang.*; public class cmdemp58 { public static void main(String r[ ])throws Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:Example","scott","tiger"); Statement st=con.createStatement(); int eno1=Integer.parseInt(r[0]); String ename1=r[1]; int esal1=Integer.parseInt(r[2]); String dept1=r[3]; int x=st.executeUpdate("Insert into emp values("+eno1+",'"+ename1+"',"+esal1+",'"+dept1+"')"); if(x>0) System.out.println("1 row is inserted"); else System.out.println("error"); } }

Aim: Java Program to Update values of a table through Command Prompt. Source code:
import java.sql.*; import java.io.*; import java.lang.*; public class cmdupdemp { public static void main(String r[ ])throws Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:Example","scott","tiger"); Statement st=con.createStatement(); int sal=Integer.parseInt(r[0]); int i=st.executeUpdate("update emp set esal=esal+"+sal+""); if(i>0) System.out.println("rows updated"+i); else System.out.println("error"); } }

Aim: Java Program to Delete values from table through Command Prompt. Source code:
import java.sql.*; import java.io.*; import java.lang.*; public class cmddelemp { public static void main(String r[ ])throws Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:Example","scott","tiger"); Statement st=con.createStatement(); int amt=Integer.parseInt(r[0]); int i=st.executeUpdate("delete from emp where esal<"+amt+""); if(i>0) System.out.println("rows deleted="+i); else System.out.println("error"); } }

Aim: Java Program to Insert values into a table using Prepared Statements. Source code:
import java.io.*; import java.sql.*; public class preinsert { public static void main(String args[])throws Exception { Class .forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:siva","scott","tiger"); PreparedStatement pt=con.prepareStatement("insert into emp593 values(?,?,?,?)"); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); while(true) { System.out.println("enter eno,ename,esal,dept"); int eno=Integer.parseInt(br.readLine()); String ename=br.readLine(); int esal=Integer.parseInt(br.readLine()); String dept=br.readLine(); pt.setInt(1,eno); pt.setString(2,ename); pt.setInt(3,esal); pt.setString(4,dept); pt.executeUpdate(); System.out.println("Do you want another (yes/no)"); String ch=br.readLine(); if(!ch.equalsIgnoreCase("yes")) break; } con.close(); } }

Aim: Java Program to Update values of a table using Prepared Statements. Source code:
import java.io.*; import java.sql.*; public class preupd { public static void main(String args[])throws Exception { Class .forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:siva","scott","tiger"); PreparedStatement pt=con.prepareStatement("update emp593 set esal=esal+(?) where eno=593"); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); while(true) { System.out.println("enter esal to be updated"); int esal=Integer.parseInt(br.readLine()); pt.setInt(1,esal); pt.executeUpdate(); System.out.println("do u want to continue(y/n)"); String ch=br.readLine(); if(!ch.equalsIgnoreCase("y")) break; } } }

Aim: Java Program to Delete values from a table using Prepared Statements. Source code:
import java.io.*; import java.sql.*; public class predel { public static void main(String args[])throws Exception { Class .forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:siva","scott","tiger"); PreparedStatement pt=con.prepareStatement("delete from emp593 where ename=(?)"); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); while(true) { System.out.println("enter ename to be deleted"); String ename=br.readLine(); pt.setString(1,ename); pt.executeUpdate(); System.out.println("do u want to continue(y/n)"); String ch=br.readLine(); if(!ch.equalsIgnoreCase("y")) break; } } }

Aim: Java Program to Select values from a table using Prepared Statements. Source code:
import java.sql.*; import java.io.*; import java.lang.*; public class Prep_select { public static void main(String args[])throws Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:Emp","scott","tiger"); InputStreamReader isr=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(isr); PreparedStatement ps=con.prepareStatement("select * from Employeewt where esal<? ") ; while(true) { System.out.println("enter esal for which selection is required"); int esal=Integer.parseInt(br.readLine()); ps.setInt(1,esal); ResultSet rs=ps.executeQuery(); while(rs.next()) { System.out.println(rs.getInt(1) +"\t" +rs.getString(2) +"\t" +rs.getInt(3) +"\t" +rs.getString(4)); } System.out.println("do you want to continue y/n"); String ch=br.readLine(); if(!ch.equalsIgnoreCase("y")) break; } } }

Aim: Java Program to Insert values into a table using Callable Statements. Source code:
import java.sql.*; class Stored_insert { public static void main(String args[])throws Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:Emp","scott","tiger"); CallableStatement cst=con.prepareCall("{call insert_values()}"); cst.execute(); } }

Aim: Java Program to Update values of a table using Callable Statements. Source code:
import java.io.*; import java.sql.*; class Stored_update { public static void main(String args[])throws Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:Emp","scott","tiger"); InputStreamReader isr=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(isr); System.out.println("enter no"); int eno=Integer.parseInt(br.readLine()); CallableStatement cst=con.prepareCall("{call update_values(?,?)}"); cst.setInt(1,eno); cst.registerOutParameter(2,Types.INTEGER); cst.execute(); //System.out.println(cst.getInt(1)); } }

Aim: Java Program to Delete values from a table using Callable Statements. Source code:
import java.sql.*; class Stored_del { public static void main(String args[])throws Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:Emp98","scott","tiger"); CallableStatement cst=con.prepareCall("{call del_values98()}"); cst.execute(); } }

Aim: Java Program implementing ResultSetMetaData Interface. Source code:


import java.io.*; import java.lang.*; import java.sql.*; public class rsmd { public static void main(String args[])throws Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:emp79","scott","tiger"); Statement st=con.createStatement(); ResultSet rs=st.executeQuery("select * from emp"); ResultSetMetaData rsmd=rs.getMetaData(); int x=rsmd.getColumnCount(); for(int i=1;i<=x;i++) System.out.println(rsmd.getColumnName(i)+";"+rsmd.getColumnTypeName(i)+";"+rsmd.getCo lumnDisplaySize(i)); } }

Aim: Java Program implementing DataBaseMetaData Interface. Source code:


import java.io.*; import java.lang.*; import java.sql.*; public class dbmd { public static void main(String args[])throws Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:emp79","scott","tiger"); DatabaseMetaData dbmd=con.getMetaData(); System.out.println(dbmd.getDatabaseProductName()+";"+dbmd.getDatabaseProductVersion()+" ;"+dbmd.getDriverVersion()+";"+dbmd.getSQLKeywords()+";"+dbmd.getStringFunctions()+";" +dbmd.getNumericFunctions()+";"+dbmd.supportsStoredProcedures()); } }

Aim: Program on basics of Servlets. Source code:


Java file: import java.io.*; import javax.servlet.*; public class first extends GenericServlet { public void service(ServletRequest req,ServletResponse res)throws IOException,ServletException { res.setContentType("text/html"); PrintWriter pw=res.getWriter(); pw.println("<html>"); pw.println("<b>Hello servlet"); pw.println("</html>"); pw.close(); } } XML file: <web-app> <servlet> <servlet-name>first</servlet-name> <servlet-class>first</servlet-class> </servlet> <servlet-mapping> <servlet-name>first</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> </web-app>

Вам также может понравиться