Friday, October 3, 2008

Inserting database values into the String array in java struts using jdbc

Here is the sample method code is given which is inserting the database values in String array variable.

public String[] findGRNumbers(String branch,String course,String trimester,int size) throws DataAccessException,java.sql.SQLException{

MYSQLConnect connect=new MYSQLConnect();

Connection conn = connect.connection;

Statement smt = conn.createStatement();

ResultSet rs;

int no=0;

String[]str=new String[size];

//write select query for checking password

String query="select gr_number,roll_number,student_name from

student_master where branch='"+branch+"' and

course='"+course+"' and trimester='"+trimester+"'";

rs=smt.executeQuery(query);

while(rs.next()== true){

str[no]=rs.getString("gr_number");

no++;

}

smt.close();

rs.close();

conn.close();

return str;

}

No comments: