R4R Team working to provide free of cost for experienced and freshers

Tutorials | Examples|Interview Questions and Answers|Java Tutorials| C Tutorials | C++ Tutorials | Spring Tutorials| Hibernate Tutorials | JSP Tutorials | Servelets Tutorials| C# Tutorials | PHP Tutorials etc , Basics | Download Software | Data Types | Variables | Constant | Storage & Classes | Operators | Decisions Making | Loops | Functions| Numbers | Arrays | Pointers | String | Datastructure | Expressions | Preprocessor Statement | I/O | Exception Handling | OOPs Tutorial | Classes and object |C++ Inheritance Overloading | Polymorphism | Abstraction | Encapsulation | Interfaces | Multithreading etc

JDBC

JDBC Projects

JDBC Project 1

JDBC Using Statement example Select record using name:-
Previous Home Next
/* This program shows you how to fetch a row by
providing the unique name from the database 
table using JDBC Statement.*/

package r4r;
import java.sql.*;
import java.util.*;
public class FetchByName {
public static void main(String[] args) {
try
{
Scanner s=new Scanner(System.in);
System.out.println("Enter your name:-");
String s1=s.nextLine();
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection
("jdbc:oracle:thin:@localhost:1521:xe","system","oracle");
Statement stmt=con.createStatement();
ResultSet rset=stmt.executeQuery("select *
from user5 where name='"+s1+"'");
while(rset.next())
{
System.out.println
(rset.getString(1)+"\t"+rset.getInt(2)+"\t"
+rset.getString(3)+"\t"+rset.getString(4));
System.out.println("successfully fetched");
}
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}

output:

Enter your name:-
gaurav
The fetched data are:-
gaurav 1 noida m
successfully fetched
Previous Home Next