Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,028

HOME > PHP > PHP Forum > ปัญหา Java web service ใช้ php เรียกใช้ service จัดการฐานข้อมูล database ไม่ได้



 

ปัญหา Java web service ใช้ php เรียกใช้ service จัดการฐานข้อมูล database ไม่ได้

 



Topic : 076297

Guest




ตอนนี้สามารถดึง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







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2012-03-28 21:59:42 By : TheCatzika View : 1244 Reply : 1
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook




Go to : PHP - Web Service กับ MySQL รับส่งค่าผ่าน Web Service กับ MySQL (NuSoap)






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-05-19 17:28:39 By : mr.win
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ปัญหา Java web service ใช้ php เรียกใช้ service จัดการฐานข้อมูล database ไม่ได้
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 02
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่