java database connectivity .

0 lacky sahu · May 14, 2015
import java.sql.*t;

import jdbc_demo_con.JDBC_con;
import oracle.jdbc.oracore.OracleType;

public class Lab16 {
public static void main(String[] args) {

Connection con=null;
CallableStatement cs=null;
ResultSet rs=null;
try{

con=JDBC_con.getConnection();

cs=con.prepareCall("call getAllStudnets(?)");
cs.registerOutParameter(1,OracleType.CURSOR);// here i am got error (CURSOR )using java 8 

cs.execute();
rs=(ResultSet) cs.getObject(1);
if(rs.next()){
do{
int id=rs.getInt(1);
String nm=rs.getString(2);
float fee=rs.getFloat(3);
System.out.println(id+"\t"+nm+"\t"+fee);
}while(rs.next());
}else{
System.out.println("NO record found");
}

}catch(Exception e){
System.out.println("Error in calling procedure");
e.printStackTrace();

}finally{
JDBC_con.cleanUp(rs,cs, con);
}
}
/*
* for oracle
* create or replace procedure getAllStudents(students OUT SYS_REFCURSOR)as
* begin
* open students for select * from students;
* end;
/
*/

}

Post a Reply

Replies

Oldest  Newest  Rating
0 Bjorn Wagner · May 15, 2015
Hi lacky
I don't know if It helps You. But since You placed the question under the Android section. You want to connect to the database frome an mobile.
I can be wrong but I don't beleave You can connect to a database this way with a jdbc data source at all.
The jbdc is not installed on android os and that should be the problem I beleave.
  • 1

Java / Android Development

107,062 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator