0% found this document useful (0 votes)
438 views1 page

Q1. Write A JDBC Program in Java To Display The Names of Employees Starting With S' Character Ans

This program uses JDBC to connect to a database and display employee names from a table that start with the letter 'S'. It connects to the database, executes a SQL query to select names like 'S%', and prints out the employee number, name, and salary for any results. The program imports the necessary libraries, establishes the connection, executes the query, iterates through the result set to display matching names, and closes the connection.

Uploaded by

Prasad Dutande
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
438 views1 page

Q1. Write A JDBC Program in Java To Display The Names of Employees Starting With S' Character Ans

This program uses JDBC to connect to a database and display employee names from a table that start with the letter 'S'. It connects to the database, executes a SQL query to select names like 'S%', and prints out the employee number, name, and salary for any results. The program imports the necessary libraries, establishes the connection, executes the query, iterates through the result set to display matching names, and closes the connection.

Uploaded by

Prasad Dutande
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Assignment:21

-----------------------------------------------------------------------------------------------------------------------------------------

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

You might also like