使用Myeclipse10建立WebService工程的配置详解(附例程)
2017-08-29 09:49
621 查看
服务器端配置如下
1.首先新建一个web service project.如下图
2.然后新建一个类,如下图
3.编写连接数据库的程序,如下
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
4.在src上点击右键选择–other–MyEclipse—web Services—web service单击next,如下图设置。
点击next如下图设置
点击Finish效果如下
5.将MySQL数据库的jar包复制到lib文件下,然后加载jax-ws的库,工程—属性下做如下图的选择,点击完成即可。
6.将工程发布到tomcat上,点击下面图标
单击add如下配置
然后如下图操作,开启tomcat
7.至此服务器端完成配置
在IE上输入网址:http://localhost:8080/WebService/WebDaoPort?wsdl,检验效果如下图
客户端配置如下
1.新建一个包client。
2.点击下面图标
点击next、然后做如下配置,next—finish即可。
完成效果如下
3.编写test类,完成数据库调用。程序如下
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
结果如下
注意事项:
1.编写数据库查询代码时,不能返回结果集(ResultSet ),webservice不支持。
2.源码:http://download.csdn.net/detail/yangghuannn/9287259
1.首先新建一个web service project.如下图
2.然后新建一个类,如下图
3.编写连接数据库的程序,如下
package server; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; public class WebDao { public Connection conn = null; public void getConnection() {// 获取连接 try {// jdbc-odbc桥接 // MySQL Class.forName("com.mysql.jdbc.Driver");// 1.加载驱动 conn = DriverManager.getConnection("jdbc:mysql://localhost/test", "root", "1234");// 2.获取连接,格式:jdbc:子协议:数据库定位器 } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } } @SuppressWarnings({ "rawtypes", "unchecked" }) public ArrayList query(String sql) {// 查询 ArrayList tcus=null; ResultSet rs = null; String account; String password; String cname; int cbalance; String number; try { getConnection(); Statement stmt = conn.createStatement();// 3.生成Statement rs = stmt.executeQuery(sql); tcus=new ArrayList(); while(rs.next()){ account=rs.getString("account"); password=rs.getString("password"); cname=rs.getString("cname"); cbalance=rs.getInt("cbalance"); number=rs.getString("number"); tcus.add(account); tcus.add(password); tcus.add(cbalance); tcus.add(number); } } catch (SQLException e) { e.printStackTrace(); } finally { close(); } return tcus; } public int update(String sql) {// 插入、删除、修改 int i = 0; try { getConnection(); Statement stmt = conn.createStatement();// 3.生成Statement i = stmt.executeUpdate(sql); } catch (SQLException e) { e.printStackTrace(); } finally { close(); } return i; } public void close() {// 关闭资源 try { if (conn != null) { conn.close(); conn = null; } } catch (SQLException e) { e.printStackTrace(); } } }1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
4.在src上点击右键选择–other–MyEclipse—web Services—web service单击next,如下图设置。
点击next如下图设置
点击Finish效果如下
5.将MySQL数据库的jar包复制到lib文件下,然后加载jax-ws的库,工程—属性下做如下图的选择,点击完成即可。
6.将工程发布到tomcat上,点击下面图标
单击add如下配置
然后如下图操作,开启tomcat
7.至此服务器端完成配置
在IE上输入网址:http://localhost:8080/WebService/WebDaoPort?wsdl,检验效果如下图
客户端配置如下
1.新建一个包client。
2.点击下面图标
点击next、然后做如下配置,next—finish即可。
完成效果如下
3.编写test类,完成数据库调用。程序如下
package test; import java.util.ArrayList; import client.WebDaoDelegate; import client.WebDaoService; public class Test { public static void main(String[] args) { // TODO Auto-generated method stub WebDaoService server = new WebDaoService(); WebDaoDelegate dd = server.getWebDaoPort(); //int result = dd.update("insert into t_customer values('44241','42441','1221121',1000,'121122')"); //System.out.println(result); @SuppressWarnings("rawtypes") ArrayList data=(ArrayList) dd.query("select * from t_customer where account='444'"); for(int i=0;i<data.size();i++){ System.out.println(data.get(i)); } } }1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
结果如下
注意事项:
1.编写数据库查询代码时,不能返回结果集(ResultSet ),webservice不支持。
2.源码:http://download.csdn.net/detail/yangghuannn/9287259
相关文章推荐
- 使用Myeclipse10建立WebService工程的配置详解(附例程)
- 利用myeclipse8.5 将使用spring配置的原工程用JAX-WS发布为webservice
- 使用XFire+Spring构建Web Service------测试工程在myeclipse的默认工作目录下的webservicetesthellworld
- 使用myeclipse快速建立webservice
- 在C++中使用sqlite的示例(从下载、编译、工程建立、配置、测试代码编写全方位介绍)
- Tomcat使用MyEclipse远程调试Java代码配置详解
- 在eclipse + MyEclipse下配置建立J2EE工程- -
- 2、使用Myeclipse 10 开发一个 WebService 应用
- MyEclipse10使用Axis2开发webservice
- Maven命令详解 模块导入 MyEclipse + Maven开发Web工程的详细配置过程
- WebService里的wsdl的详解以及使用注解修改wsdl的配置
- 在eclipse + MyEclipse下配置建立J2EE工程
- 【WebService】wsdl配置详解以及使用注解修改wsdl配置
- 使用MyEclipse开发JSP环境配置详解
- 建立一个使用.Net 2.0 MemberShip功能的标准例程——配置篇
- 在eclipse + MyEclipse下配置建立J2EE工程
- WebService里的wsdl的详解以及使用注解修改wsdl的配置
- Myeclipse2012下 使用maven 建立web工程的3种方法
- myeclipse10的Mybatis插件 Generator最完整配置详解
- 建立一个使用.Net 2.0 MemberShip功能的标准例程(二)——配置篇