|
|
|
ปัญหา Java web service ใช้ php เรียกใช้ service จัดการฐานข้อมูล database ไม่ได้ |
|
|
|
|
|
|
|
ตอนนี้สามารถดึงselectข้อมูลขึ้นมาดูได้ แต่ว่าไม่สามารถใช้งาน update,deleteได้ค่ะ
คือสามารถส่งค่าไปยังserviceได้ ไม่ติดerror แต่ว่ามันไม่เกิดการทำงานค่ะ ค่าไม่เข้าฐานข้อมูล
อย่างเช่น เรียกใช้เซอร์วิสdelete_user ได้ผลกลับมาเป็น stdClass Object ( [return] => )
code:delete.php
<?
$client = new SoapClient('http://localhost:8080/axis2/services/project?wsdl');
$para=array('user_id'=>$User);
$rs = $client->delete_user($para);
if ($client->fault) {
echo "ไม่สามารถแก้ไขรายการได้";
echo "<br>";
echo "<a href=manage.php>กลับไป</a>";
} else {
print_r($rs);
echo "แก้ไขรายการสำเร็จ";
echo "<br>";
echo "<a href=manage.php>กลับไป</a>";
}
?>
code:hr.java
package db.access;
import org.apache.axiom.om.*;
import java.sql.*;
public class project {
public project() {
// TODO Auto-generated constructor stub
}
private Connection connectDatabase( )
{
Connection con=null;
try{
Class.forName ("com.mysql.jdbc.Driver");
con = DriverManager.getConnection ("jdbc:mysql://localhost/ehr_db","root", "1234");
/*DriverManageger request for database connection*/
}
catch(ClassNotFoundException e){
e.printStackTrace();
}
catch(SQLException sql){
sql.printStackTrace();
}
return con;
}
private OMElement createXML(ResultSet rs) throws Exception
{
ResultSetMetaData rsmd = rs.getMetaData();
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace omNs = fac.createOMNamespace("http://axiom.demo/xsd", "ns");
OMElement root = fac.createOMElement ("ehr",omNs);
OMElement element,child;
while (rs.next())
{
element = fac.createOMElement ("data",omNs);
child = fac.createOMElement (rsmd.getColumnLabel(1),omNs);
child.addChild(fac.createOMText(rs.getString(1)));
element.addChild(child);
for (int i = 2; i <= rsmd.getColumnCount(); i++)
{
child =fac.createOMElement (rsmd.getColumnLabel(i),omNs);
child.addChild(fac.createOMText(rs.getString(i)));
element.addChild(child);
}
root.addChild(element);
}
return root;
}
public OMElement manage( String name )
{
Connection con=null;
Statement stmt=null;
OMElement doc =null;
try
{
con= connectDatabase();
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM User_account join Officer on User_account.user_id=Officer.user_id where Fname like '%"+name+"%'");
doc = createXML(rs);
}
catch (Exception e)
{
e.printStackTrace( );
}
finally
{
try
{
con.close();
stmt.close();
}
catch(SQLException e)
{
e.printStackTrace( );
}
}
return doc;
}
public OMElement update_user( String sex,int posit,String fname,String lname,int salary, String address,String email,String tel,String special,String enddate,String skill,String research,String train,String edu,String code )
{
Connection con=null;
Statement stmt=null;
OMElement doc =null;
try
{
con= connectDatabase();
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("update Officer set Sex='"+sex+"', Position_id='"+posit+"',Fname='"+fname+"',Lname='"+lname+"', Salary='"+salary+"',Address='"+address+"',Email='"+email+"',Tel='"+tel+"', Special_ability='"+special+"',End_date='"+enddate+"',Skill='"+skill+"', Research='"+research+"',Training='"+train+"',Education='"+edu+"' where User_id='"+code+"'");
doc = createXML(rs);
}
catch (Exception e)
{
e.printStackTrace( );
}
finally
{
try
{
con.close();
stmt.close();
}
catch(SQLException e)
{
e.printStackTrace( );
}
}
return doc;
}
public OMElement delete_user( String user_id )
{
Connection con=null;
Statement stmt=null;
OMElement doc =null;
try
{
con= connectDatabase();
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("delete from User_account where User_id='"+user_id+"'");
doc = createXML(rs);
}
catch (Exception e)
{
e.printStackTrace( );
}
finally
{
try
{
con.close();
stmt.close();
}
catch(SQLException e)
{
e.printStackTrace( );
}
}
return doc;
}
}
Tag : PHP, MySQL, WebService
|
|
|
|
|
|
Date :
2012-03-28 21:59:42 |
By :
TheCatzika |
View :
1278 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|