Q1. Write A JDBC Program in Java To Display The Names of Employees Starting With S' Character Ans
Q1. Write A JDBC Program in Java To Display The Names of Employees Starting With S' Character Ans
-----------------------------------------------------------------------------------------------------------------------------------------
Q1. Write a JDBC Program in java to display the names of Employees starting with S character
Ans:
import java.sql.*;
import java.io.*;
class Journal8_1
{
public static void main(String args[])throws IOException
{
Connection cn;
Statement st;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String s;
ResultSet rs;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
cn=DriverManager.getConnection("jdbc:odbc:dt");
st=cn.createStatement();
s="select * from emp where ename like 'S%'";
rs=st.executeQuery(s);
System.out.println("Displaying Employee Names Starting with S ");
while(rs.next())
{
System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getInt(3));
}
cn.close();
st.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
OUTPUT
C:\Users\Onkar\Desktop >javac Journal8_1.java
C:\Users\ Onkar\Desktop>java Journal8_1
Displaying Employee Names Starting with S
101 Ajinkya 15000
103 Gourav 12500
105 Shubham 16500