`
cuiran
  • 浏览: 81088 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

java连接数据库

阅读更多
package text;

import java.rmi.RemoteException;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Vector;

import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.TypeMapping;
import org.apache.axis.encoding.TypeMappingDelegate;
import org.apache.axis.encoding.XMLType;

public class TestSql {

/**
* @param args
*/
Call  call=null;
public TestSql(){
try{
String endpointURL = "http://localhost:8080/axis/BaseDaoImp.jws";
         System.out.println("axis");
         Service  service = new Service();
         call  = (Call) service.createCall();
         call.setTargetEndpointAddress(new java.net.URL(endpointURL) );
} catch (Exception e) {
            System.err.println(e.toString());
        }

}
public void del(){
  //删除成功
        call.setOperationName(new QName("BaseDaoImp","execUpdate"));
        call.addParameter("op1", XMLType.XSD_INT, ParameterMode.IN);
        call.setReturnType(XMLType.XSD_INT);
        Integer n=null;
try {
n = (Integer)call.invoke(new Object[]{"delete admin where  name='b'"});
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
        System.out.println(n);
}
public void list(){
try {
    call.setOperationName(new QName("BaseDaoImp","list"));
        call.addParameter("op1", XMLType.AXIS_VOID, ParameterMode.IN);
        call.setReturnType(XMLType.AXIS_VOID);
    call.invoke();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void getVector(){
try {
    call.setOperationName(new QName("BaseDaoImp","getVector"));
        call.addParameter("op1", XMLType.XSD_ANYTYPE, ParameterMode.IN);
        call.setReturnType(XMLType.XSD_ANYTYPE);
Vector<String>  v=(Vector<String>)call.invoke(new Object[]{"select * from admin"});
System.out.println(v.size());
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void getArrayList(){
try {
    call.setOperationName(new QName("BaseDaoImp","getArrayList"));
        call.addParameter("op1", XMLType.XSD_ANYTYPE, ParameterMode.IN);
        call.setReturnType(XMLType.XSD_ANYTYPE);
        ArrayList<String>  v=(ArrayList<String>)call.invoke(new Object[]{"select * from admin"});
System.out.println("getArrayList"+v.size());
} catch (RemoteException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
TestSql t=new TestSql();
// t.del();
// t.list();
//     t.getVector();
t.getArrayList();
}

}
  • 大小: 215.8 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics