.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Home >> Code Snippets >> Javascript >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Search Records using Jdbc

Posted By:satyapriyanayak       Posted Date: October 02, 2014    Points: 40    Category: Javascript    URL: http://www.dotnetspark.com  

In this Code Snippets we will know how to find the related records from the table when we enter one field value in console.

Here we use Type-1 driver (JDBC-ODBC bridge)

Creation of dsn(database source name) for Oracle
Start-Control panel- Administrative Tools- Data Sources (ODBC)-go to system dsn tab-click add button-select a driver for which you want to set up data source (for Oracle- Oracle in XE)-select it and click finish-give any name in data source name textbox-then click ok button.

Note: - Here Username=system, Password=pintu and Dsn name= dsn1

Table Creation with values

create table emp(empno int,empname varchar(50),sal int,job varchar(50))
insert into emp values(1,'Raj',10000,'Manager')
insert into emp values(2,'Ravi',20000,'Director')
insert into emp values(3,'Rahul',30000,'Producer')


import java.sql.*;
import java.util.*;
public class SearchRecords
public static void main(String args[]) throws Exception
int eno,esal;
String ename,job;
char ch='c';
Scanner sc=new Scanner(System.in);
Connection con=DriverManager.getConnection("jdbc:odbc:dsn1","system","pintu");
ResultSet rs;
Statement stmt=con.createStatement();
System.out.print("\nEnter the Employee Number : ");
rs=stmt.executeQuery("select * from emp where empno like "+eno);
System.out.println("\nNAME: "+ename+" ENO: "+eno+" Job: "+job);
System.out.println("\nPress any key to quit or c to continue :");
while(ch=='c' || ch=='C');


Javac SearchRecords.java
Java SearchRecords


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend