myeclipse在j2ee工程中webservice连接数据库问题!
发布网友
发布时间:2022-04-09 02:12
我来回答
共3个回答
热心网友
时间:2022-04-09 03:41
package demo.ws.server;
import java.sql.*;
import javax.jws.WebService;
@WebService(endpointInterface = "demo.ws.server.HelloWorld", serviceName
= "HelloWorld")
public class HelloWorldImp implements HelloWorld {
public String sayHi(int text) {
// TODO Auto-generated method stub
String url ="jdbc:oracle:thin:@211.87.228.118:1521:ORCL";
String user="DBSNMP";
String password="wangjing";
int SNO=text;
String query = "select NAME from HOSTEL where SNO='"+SNO+"'";
String col2=" ";
try{
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
Connection con= DriverManager.getConnection(url,user,password);
Statement stmt = con.createStatement();
ResultSet rs= stmt.executeQuery(query);
while(rs.next())
{
col2=rs.getString("NAME");
}
rs.close();
stmt.close();
con.close();
}
catch(SQLException ex){}
catch(java.lang.Exception ex){ex.printStackTrace();}
return col2;
}
public void hello(String name) {
System.out.println("/////////////: the Oneway method," +
name);
}
public String hi(String name) {
System.out.println("in method String hi(String name): " +
name);
return "Hi, " + name;
}
}
这是个例子,相信你能看懂追问肥水不流外人田,给你吧 -.- #
热心网友
时间:2022-04-09 04:59
建web project 就行了
web service project看名字就知道不是你需要的
热心网友
时间:2022-04-09 06:34
用XFire吧,XFire比较简单,搜一下XFire的资料。自己多动手。