浏览 1441 次
锁定老帖子 主题:java连接数据库
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2008-11-26
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(); } } 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |