In this example demonstrate the Microsoft access(odbc) connectivity database contain the bank table with sr_no,name,Ac.no,balance,ph.no.
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Connectivity {
public static void main(String args[]){
try {
Connection c;
Statement st;
ResultSet r;
Class.forName("sun.jdbc.odbc.JdcbOdbcDrive");
c = DriverManager.getConnection("jdbc:odbc:Pruthvi”);
st = c.createStatement();
st.executeUpdate("insert into Bank(name,account_no,balance,pn_no) values('uttam',1005,10512,1612)");
r = st.executeQuery("select * from Bank");
System.out.println("Sr.No."+"\t"+"Name"+"\t"+"Ac.No."+"\t"+"Balance"+"\t"+"Ph.No");
while (r.next()) {
System.out.print(r.getInt(1)+"\t");
System.out.print(r.getString(2)+"\t");
System.out.print(r.getInt(3)+"\t");
System.out.print(r.getInt(4)+"\t");
System.out.print(r.getInt(5)+"\t");
System.out.println("");
}
c.close();
st.close();
} catch (SQLException ex) {
Logger.getLogger(Connectivity.class.getName()).log(Level.SEVERE, null, ex);
} catch (ClassNotFoundException ex) {
Logger.getLogger(Connectivity.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
No comments:
Post a Comment