
hey friends....
plz me to solve this question...
I have used the following code for retrieving data fromm two tables : first table having fields: bookid,name,phno second table having field: seat-id
But the data is not retrieved:why so???
1)first -.java file
package pack;
public class admin {
private int Book_id;
private String name;
public int getBook_id() {
return Book_id;
}
public void setBook_id(int Book_id) {
this.Book_id = Book_id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getPh_no() {
return ph_no;
}
public void setPh_no(int ph_no) {
this.ph_no = ph_no;
}
private int ph_no;
}
2). .java file
package pack; import java.sql.*;
import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.logging.Level; import java.util.logging.Logger;
public class admindao { Connection con; public admindao(){ try { Class.forName("com.mysql.jdbc.Driver"); con = DriverManager.getConnection("jdbc:mysql://localhost:3306/ips?user=root&password=mysql"); } catch (SQLException ex) { Logger.getLogger(admindao.class.getName()).log(Level.SEVERE, null, ex); } catch (ClassNotFoundException ex) { Logger.getLogger(admindao.class.getName()).log(Level.SEVERE, null, ex); }
}
public ArrayList
try {
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select B.book_id,B.name,B.phoneno from booking_table B");
while (rs.next()) {
admin u1 = new admin();
u1.setBook_id(rs.getInt(1));
u1.setName(rs.getString(2));
u1.setPh_no(rs.getInt(3));
// u1.setSeat_no(rs.getInt(2));
list.add(u1);
}
} catch (SQLException ex) {
Logger.getLogger(admindao.class.getName()).log(Level.SEVERE, null, ex);
}
return list;
} }
3).second .java file for getting data from second table-
package pack;
public class table2 { private int seat_no;
public int getSeat_no() {
return seat_no;
}
public void setSeat_no(int seat_no) {
this.seat_no = seat_no;
}
} 4)..java for second table_
package pack; import java.sql.*; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.logging.Level; import java.util.logging.Logger;
public class table2dao{ Connection con1; public table2dao(){ try { Class.forName("com.mysql.jdbc.Driver"); con1 = DriverManager.getConnection("jdbc:mysql://localhost:3306/ips?user=root&password=mysql"); } catch (SQLException ex) { Logger.getLogger(table2dao.class.getName()).log(Level.SEVERE, null, ex); } catch (ClassNotFoundException ex) { Logger.getLogger(table2dao.class.getName()).log(Level.SEVERE, null, ex); }
}
public ArrayList
try {
Statement stmt = con1.createStatement();
ResultSet rs1 = stmt.executeQuery("select seat_id from booked_table ");
while (rs1.next()) {
table2 u1 = new table2();
u1.setSeat_no(rs1.getInt(2));
list1.add(u1);
}
} catch (SQLException ex) {
Logger.getLogger(table2dao.class.getName()).log(Level.SEVERE, null, ex);
}
return list1;
} }
5)..jsp file-
<%@page import="java.util.*"%> <%@page import="java.util.ArrayList"%> <%@page import="pack.*"%> <%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.