Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @WebService(serviceName = "download")
- public class download
- {
- Connection con=null;
- private DataSource getJdbcPostgres() throws NamingException, SQLException
- {
- Context c = new InitialContext();
- DataSource ds=(DataSource) c.lookup("java:comp/env/jdbc/postgres");
- con=ds.getConnection();
- return ds;
- }
- @WebMethod(operationName = "download")
- public String download(@WebParam(name = "username")String username, @WebParam(name = "id")String id) throws ClassNotFoundException, SQLException
- {
- String sql="select * from test where id="+id;
- Class.forName("org.postgresql.Driver");
- PreparedStatement pst=con.prepareStatement(sql);
- ResultSet rs=pst.executeQuery();
- ResultSetMetaData rsmd=rs.getMetaData();
- rs.next();
- return "";
- }
- }
- <?xml version="1.0" encoding="UTF-8"?>
- <Context path="/service2">
- <Resource name="jdbc/postgres" auth="Container"
- type="javax.sql.DataSource" driverClassName="org.postgresql.Driver"
- url="jdbc:postgresql://localhost:5432/postgres"
- username="someusername" password="somepassword" maxTotal="20" maxIdle="10"
- maxWaitMillis="-1"/>
- </Context>
- <?xml version="1.0" encoding="UTF-8"?>
- <web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
- http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
- <listener>
- <listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
- </listener>
- <servlet>
- <servlet-name>download</servlet-name>
- <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
- <load-on-startup>1</load-on-startup>
- </servlet>
- <servlet-mapping>
- <servlet-name>download</servlet-name>
- <url-pattern>/download</url-pattern>
- </servlet-mapping>
- <session-config>
- <session-timeout>
- 30
- </session-timeout>
- </session-config>
- <resource-ref>
- <description>postgreSQL Datasource example</description>
- <res-ref-name>jdbc/postgres</res-ref-name>
- <res-type>javax.sql.DataSource</res-type>
- <res-auth>Container</res-auth>
- </resource-ref>
- </web-app>
- Checking data source definitions for missing JDBC drivers...
- Undeploying ...
- undeploy?path=/service2
- OK - Undeployed application at context path /service2
- In-place deployment at D:NetBeansProjectsservice2buildweb
- Deployment is in progress...
- deploy?config=file%3A%2FC%3A%2FUsers%2FTRAINE%7E3%2FAppData%2FLocal%2FTemp%2Fcontext1366288511044657094.xml&path=/service2
- FAIL - Deployed application at context path /service2 but context failed to start
- D:NetBeansProjectsservice2nbprojectbuild-impl.xml:1094: The module has not been deployed.
- See the server log for details.
- BUILD FAILED (total time: 2 seconds)
Add Comment
Please, Sign In to add comment