what is jdbc?
Answers were Sorted based on User's Feedback
Answer / nagendar.m
Hi ammu the interviewer doesn't mean to ask the abrivation
of the jdbc.
see, i can justify my ans for this Q? hav a look.
jdbc is an API provided to connet various DB's from a java
program and as part of jdbc there are 4 types of drivers
avilable to connect DB.
>Type-I to Type-IV
>in projects we use Type-IV driver which is called Thin
driver OR we use the combination of thin and Type-III
driver.
>Sample code: Using Thin driver and Oracle DB.
Class.forName("Oracle.jdbc.driver.OracleDriver");
String url="jdbc:oracle:thin:@localhost:1521:server";
Connection connection=DriverManager.getConnection
(url,"SCOTT","TIGER");
PreparedStatement ps=connection.prepareStatement("SELECT *
FROM EMPLOYEE");
ResultSet rs=ps.executeQuery();
i think this Explination is fine...
Is This Answer Correct ? | 28 Yes | 0 No |
Answer / rice
Java database connectivity is a service technology from sun
micro systems.
It is a J2EE service technology from sun micro systems.
The main objective of this service technology is to persist
the Java Object state into the file system permanently.i.e
store the Java Object state into Relational model i.e in
database product.
Is This Answer Correct ? | 0 Yes | 1 No |
Answer / rohil
JDBC IS JAVA DATABASE CONNECTIVITY
this is used to get our java code connected with database
so that everytime we execute our code we dont have to start
from beginnning ...ie again making objects and giving
values again...with databse connectivty u can store the
data once and for all...
package com.mypack;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.*;
import oracle.jdbc.driver.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet Class
*
* @web.servlet name="CDataAccess"
* display-name="Name for
CDataAccess"
* description="Description for
CDataAccess"
* @web.servlet-mapping url-pattern="/CDataAccess"
* @web.servlet-init-param name="A parameter"
* value="A value"
*/
public class CDataAccess extends HttpServlet {
Connection con=null;
Statement st=null;
PrintWriter out=null;
ResultSet rs=null;
public CDataAccess() {
super();
// TODO Auto-generated constructor stub
}
protected void doGet(HttpServletRequest req,
HttpServletResponse resp)
throws ServletException,
IOException {
// TODO Auto-generated method stub
//super.doGet(req, resp);
out=resp.getWriter();
String prodId=(String)req.getParameter
("txtProdId");
String prodName=(String)req.getParameter
("txtProdName");
try
{
//register the driver with the
application
DriverManager.registerDriver(new
oracle.jdbc.OracleDriver());
//connecting with the database
con=DriverManager.getConnection
("jdbc:oracle:thin:databse name:1521:javadb","name of
server","password");
//Connection c=getCon();
if(!con.isClosed() )
{
out.println("Connection
established");
st=con.createStatement();//creates
an object of statement
String query="insert into Products
values('"+prodId+"','"+prodName+"')";
int i=st.executeUpdate(query);
if(i>0)
{
out.println("Data
inserted"+"<br/>");
}
String q="select * from Products";
rs=st.executeQuery(q);
while(rs.next())
{
out.println(rs.getString
("PID")+","+rs.getString("PNAME")+"<br/>");
}
st.close();
}
}
catch(SQLException ex){
out.println(ex.getMessage());
}
}
Is This Answer Correct ? | 0 Yes | 3 No |
What's the difference between authentication and authorization? : java security
What are the disadvantages of java sockets?
How can I write a program that takes command line input?
What is rxjava2?
What is a java proxy?
What if I do not provide the string array as the argument to the method?
differences between iterator and spliterator in java se 8?
Which class is the superclass of every class?
What about 'hostile applets'? : java security
What is web container in java?
what is reflection api? How are they implemented?
How do I open my java console?