Guest User

Untitled

a guest
Jun 26th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. @WebService(serviceName = "download")
  2. public class download
  3.  
  4. {
  5.  
  6.  
  7. Connection con=null;
  8.  
  9. private DataSource getJdbcPostgres() throws NamingException, SQLException
  10.  
  11. {
  12. Context c = new InitialContext();
  13. DataSource ds=(DataSource) c.lookup("java:comp/env/jdbc/postgres");
  14. con=ds.getConnection();
  15. return ds;
  16. }
  17.  
  18.  
  19.  
  20. @WebMethod(operationName = "download")
  21. public String download(@WebParam(name = "username")String username, @WebParam(name = "id")String id) throws ClassNotFoundException, SQLException
  22. {
  23.  
  24. String sql="select * from test where id="+id;
  25.  
  26. Class.forName("org.postgresql.Driver");
  27.  
  28. PreparedStatement pst=con.prepareStatement(sql);
  29. ResultSet rs=pst.executeQuery();
  30. ResultSetMetaData rsmd=rs.getMetaData();
  31. rs.next();
  32.  
  33. return "";
  34. }
  35.  
  36. }
  37.  
  38. <?xml version="1.0" encoding="UTF-8"?>
  39. <Context path="/service2">
  40. <Resource name="jdbc/postgres" auth="Container"
  41. type="javax.sql.DataSource" driverClassName="org.postgresql.Driver"
  42. url="jdbc:postgresql://localhost:5432/postgres"
  43. username="someusername" password="somepassword" maxTotal="20" maxIdle="10"
  44. maxWaitMillis="-1"/>
  45. </Context>
  46.  
  47. <?xml version="1.0" encoding="UTF-8"?>
  48. <web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
  49. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  50. xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
  51. http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
  52. <listener>
  53. <listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
  54. </listener>
  55. <servlet>
  56. <servlet-name>download</servlet-name>
  57. <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
  58. <load-on-startup>1</load-on-startup>
  59. </servlet>
  60. <servlet-mapping>
  61. <servlet-name>download</servlet-name>
  62. <url-pattern>/download</url-pattern>
  63. </servlet-mapping>
  64. <session-config>
  65. <session-timeout>
  66. 30
  67. </session-timeout>
  68. </session-config>
  69. <resource-ref>
  70. <description>postgreSQL Datasource example</description>
  71. <res-ref-name>jdbc/postgres</res-ref-name>
  72. <res-type>javax.sql.DataSource</res-type>
  73. <res-auth>Container</res-auth>
  74. </resource-ref>
  75. </web-app>
  76.  
  77. Checking data source definitions for missing JDBC drivers...
  78. Undeploying ...
  79. undeploy?path=/service2
  80. OK - Undeployed application at context path /service2
  81. In-place deployment at D:NetBeansProjectsservice2buildweb
  82. Deployment is in progress...
  83. deploy?config=file%3A%2FC%3A%2FUsers%2FTRAINE%7E3%2FAppData%2FLocal%2FTemp%2Fcontext1366288511044657094.xml&path=/service2
  84. FAIL - Deployed application at context path /service2 but context failed to start
  85. D:NetBeansProjectsservice2nbprojectbuild-impl.xml:1094: The module has not been deployed.
  86. See the server log for details.
  87. BUILD FAILED (total time: 2 seconds)
Add Comment
Please, Sign In to add comment