dcsimg
getting last record
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   sreeja_jayant
Posted On:   Wednesday, August 7, 2002 01:55 AM

The following is the bean which handles opening connection,closing connection,executing query,getting last record. import java.sql.*; import java.util.Vector; public class BackEnd { private Connection con; private Statement stmt; private PreparedStatement pstmt; ResultSet rs1; public static void main(String args[]){ BackEnd bck = new BackEnd(); }//end of main public BackEnd(){ System.out.println("In Backend") ; openSession() ; } public int getLast(){ int i=0; this.executeQry("select max(doc_id) from dms") ; try { if(rs1.first()) i= rs1.getInt(1) ;    More>>
			
The following is the bean which handles opening connection,closing connection,executing query,getting last record.


import java.sql.*;
import java.util.Vector;

public class BackEnd {
private Connection con;
private Statement stmt;
private PreparedStatement pstmt;
ResultSet rs1;

public static void main(String args[]){
BackEnd bck = new BackEnd();
}//end of main

public BackEnd(){
System.out.println("In Backend") ;
openSession() ;
}

public int getLast(){
int i=0;
this.executeQry("select max(doc_id) from dms") ;
try {
if(rs1.first())
i= rs1.getInt(1) ;
}catch(SQLException e){System.out.print(e.getMessage());}
return i ;
}

public Vector getData(){
Vector vt = new Vector() ;
if(rs1 != null){
try {
rs1.first() ;
vt.addElement(rs1.getString("dt"));
vt.addElement(rs1.getString("ti"));
vt.addElement(rs1.getString("au"));
vt.addElement(rs1.getString("cs"));
vt.addElement(rs1.getString("dno"));
vt.addElement(rs1.getString("ky"));
vt.addElement(rs1.getString("cc"));
vt.addElement(rs1.getString("dl"));
vt.addElement(rs1.getString("notes"));
vt.addElement(rs1.getString("ufn"));
vt.addElement(rs1.getString("doc_id"));

}catch(Exception e){
System.out.println("1" + e.getMessage()) ;
}
}
return vt;
}

public void openSession() {
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
System.out.println("Oracle Driver Registered") ;
con = DriverManager.getConnection ("jdbc:oracle:thin:@172.16.2.50:1521:ncl", "ddims","sjk");
System.out.println("Connection 2 Established") ;
}catch(Exception e) {
System.out.println("Connection Failed") ;
}
}

public void executeQry(String str) {
try {
stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE) ;
System.out.println("Statement Established") ;
System.out.println(str) ;
stmt.execute(str) ;
rs1 = stmt.getResultSet() ;
}
catch(SQLException e) {
System.out.println(e.getMessage()) ;
}
}
public PreparedStatement exeQry(String qry)throws SQLException {
pstmt = con.prepareStatement(qry) ;
return pstmt ;
}

public ResultSet getResultset() {
return rs1 ;
}

public Connection getConnection() {
return con ;
}

public void closeSession() {
try{
con.close();
}//end of try
catch(Exception e){
System.out.println("caught exception " + e.getMessage());
}
}

protected void finalize() {
try {
if(stmt != null)
stmt.close() ;
if(con != null)
con.close() ;
}catch(SQLException se) {}
}

}//end of backend class

But sometimes it doesn't show last record to be correct.the record no doesn't get incremented while adding new record.
.    <<Less
About | Sitemap | Contact