Jdbc jdbc java Database Connectivity



Download 73,83 Kb.
Sana22.01.2022
Hajmi73,83 Kb.
#398683
Bog'liq
JDBC

JDBC

JDBC - Java Database Connectivity

JDBC API

  • Driver interface
  • Connection interface
  • Statement interface
  • PreparedStatement interface
  • CallableStatement interface
  • ResultSet interface
  • ResultSetMetaData interface
  • DatabaseMetaData interface
  • RowSet interface

JDBC

Bazaga ulanish va ma’lumotlarni olish

try{  

Class.forName("com.mysql.jdbc.Driver");  

Connection con=DriverManager.getConnection(  

"jdbc:mysql://localhost:3306/mydb","root","root");  

Statement stmt=con.createStatement();  

ResultSet rs=stmt.executeQuery("select * from emp");  

while(rs.next())  

System.out.println(rs.getInt(1)+"  "+rs.getString(2)+"  "+rs.getString(3));  

con.close();  

}catch(Exception e){ 

System.out.println(e);

}    

INSERT/UPDATE/DELETE

Class.forName(" com.mysql.jdbc.Driver");  

Connection con=DriverManager.getConnection(" jdbc:mysql://localhost:3306/mydb ",“root",“root");  

Statement stmt=con.createStatement();  

  

//stmt.executeUpdate("insert into emp765 values(33,'Irfan',50000)");  

//int result=stmt.executeUpdate("update emp765 set name='Vimal',salary=10000 where id=33");  

int result=stmt.executeUpdate("delete from emp765 where id=33");  

System.out.println(result+" records affected");  

con.close();  

ResultSet

Statement stmt=con.createStatement(

ResultSet.TYPE_SCROLL_SENSITIVE,

ResultSet.CONCUR_UPDATABLE);  

ResultSet rs=stmt.executeQuery("select * from emp765");  

  

//getting the record of 3rd row  

rs.absolute(3);  

System.out.println(rs.getString(1)+" "+rs.getString(2)+" "+rs.getString(3));  

ResultSet methods


1) public boolean next():

2) public boolean previous():

3) public boolean first():

4) public boolean last():

5) public boolean absolute(int row):

6) public boolean relative(int row):

7) public int getInt(int columnIndex):

8) public int getInt(String columnName):

9) public String getString(int columnIndex):

10) public String getString(String columnName):

PreparedStatement


PreparedStatement stmt=con.prepareStatement("insert into Emp values(?,?)"); 

 

stmt.setInt(1,101);   



stmt.setString(2,"Ratan");  

  

int i=stmt.executeUpdate();  

System.out.println(i+" records inserted");  

  

con.close();  


PreparedStatement


UPDATE

PreparedStatement stmt=con.prepareStatement("update emp set name=? where id=?");  

stmt.setString(1,“John");

stmt.setInt(2,101);  

  

int i=stmt.executeUpdate();  

System.out.println(i+" records updated"); 


PreparedStatement


DELETE

PreparedStatement stmt=con.prepareStatement("delete from emp where id=?");  

stmt.setInt(1,101);  

  

int i=stmt.executeUpdate();  

System.out.println(i+" records deleted");  

SELECT


PreparedStatement stmt=con.prepareStatement("select * from emp");  

ResultSet rs=stmt.executeQuery();  



while(rs.next()){  

System.out.println(rs.getInt(1)+" "+rs.getString(2));  



}  

PreparedStatement methods


public void setInt(int paramIndex, int value)

public void setString(int paramIndex, String value)

public void setFloat(int paramIndex, float value)

public void setDouble(int paramIndex, double value)

public int executeUpdate()

public ResultSet executeQuery()

Download 73,83 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish