Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MyScalatraServlet extends ScalatraServlet with SQLServerTrait {
- var jdbcUrl = "";
- override def init(config: ServletConfig) {
- super.init(config)
- jdbcUrl = "jdbc:jtds:sqlserver://" +
- servletContext.getInitParameter("SQL_SERVER_ADDRESS") + ":" +
- servletContext.getInitParameter("SQL_SERVER_PORT") +"/" +
- servletContext.getInitParameter("SQL_SERVER_DB") + ";user=" +
- servletContext.getInitParameter("SQL_SERVER_USER") + ";password=" +
- servletContext.getInitParameter("SQL_SERVER_PASSWORD"))
- }
- before("/*") {
- contentType="application/json"
- println(jdbcUrl)
- connect(jdbcUrl)
- }
- after("/*") {
- disconnect()
- }
- notFound {
- halt(status = 404, reason = "Not Found")
- }
- options("/") {
- halt(status = 200,
- reason = "OK",
- headers = Map("Allow" -> "GET"))
- }
- get("/") {
- //Code for sending data fetched from SQL Server back to the client
- //...
- }
- }
- // test
- val servlet = new MyScalatraServlet
- servlet.jdbcUrl = testJdbcUrl
- addServlet(servlet, "/*")
Add Comment
Please, Sign In to add comment