Go4Expert

Go4Expert (http://www.go4expert.com/)
-   MS Access (http://www.go4expert.com/forums/ms-access-forum/)
-   -   problem in query (http://www.go4expert.com/forums/problem-in-query-t2369/)

qurratulain 28Dec2006 22:05

problem in query
 
sir

i m having problem while deletign and updateing the data in the tables. i m using the MS ACCESS with jsp . in which im doing work on school website project.sir i m trying to delete complete record of a teacher from all the tables related to teacher by giving the teacher id.
i m usign the query ,
stat.executeQuery(DELETE * from teacherpersonalinfo ti,
teacherjob tj where ti.ID=tj.ID AND ID='"+ID+"');
but this is giving me the problem "specify the table name".and i m able to delete the information from one table at a time , not from all.
.................................................. .......................
2nd problem;
sir i m having the problem in code for updating the teacher information in my project . i have two tables
(1)teacher-personal-info(id,name,address,age,phone,email);
(2)teacher-job(id,subjectid,salary,experience,date-of-joinig);


how can i made update the table is this right code .in this code i m trying to update the selected id from selected table by fetching the olddata from database in the form and then again inserting the data in to database .i m using the access,jsp.
check pls if there is any problem.and also tell me how can i get the result from two tables through while(rs.next()){} and print it
.........code is here........
Code:

String tid=request.getParameter("tid");
String table=request.getParameter("table");
 
if(table.equals("teacher-personal-info")){

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

Connection con=DriverManager.getConnection("jdbc:odbc:school-db");

Statement stat=con.createStatement();

ResultSet rs=stat.execute("select * from teacherinfo where tid like'"+tid+"'");
while(rs.next()){
String tid2=rs.getString(1);
String name=rs.getString(2);
String address=rs.getString(3);
String phone=rs.getString(4);
String cell=rs.getString(5);
String email=rs.getString(6);



}
}


if(table.equals("teacher-job-info")){

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

Connection con=DriverManager.getConnection("jdbc:odbc:school-db");

Statement stat=con.createStatement();

ResultSet rs= stat.execute("select * from teacher-job where tid='"+tid+"'");
while(rs.next()){
String tid2=rs.getString(1);
String name=rs.getString(2);
String address=rs.getString(3);
String phone=rs.getString(4);
String cell=rs.getString(5);
String email=rs.getString(6);



}
}
%>



<div id="text">
<form action="http://localhost:8080/school-project/teacher/update2.jsp">
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<center>Add information

</center><br/><br/><br/>
<table border="0" id="text">
<tr><td>Teacher-id&nbsp;</td><td><input type="text" name="tid" value="tid2"></td></tr>
<tr><td>Name&nbsp;</td><td><input type="text" name="name" value="name"></td></tr>
<tr><td>Address &nbsp;</td><td><input type="text" name="address" value="address"></td></tr>
<tr><td>phonE&nbsp;</td><td><input type="text" name="Phone" value="phone"></td></tr>
<tr><td>CELL# &nbsp;</td><td><input type="text" name="cellno" value="cell"></td></tr>
<tr><td>&nbsp;E-mail &nbsp;</td><td><input type="text" name="email" value="email"></td></tr>

</table>
<center><input type="submit" value="update">
<a href="teacher.html">back</a>
<br/><br/>
</center>
</form>


shabbir 28Dec2006 22:51

Re: problem in query
 
Apart from the code formating in the code block you should also provide a good title. I would suggest you aread Before you make a query

pradeep 29Dec2006 16:23

Re: problem in query
 
You can only delete from one table at a time, unless you have foreign keys specified on the related tables.


All times are GMT +5.5. The time now is 09:16.