Advertisement
Guest User

Untitled

a guest
Dec 13th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. /*
  2. * Copyright 2006 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.teamsmarteat;
  17.  
  18. import com.opensymphony.xwork2.ActionSupport;
  19.  
  20. import java.sql.Connection;
  21. import java.sql.DriverManager;
  22. import java.sql.ResultSet;
  23. import java.sql.Statement;
  24. import java.util.Date;
  25. import com.opensymphony.xwork2.conversion.annotations.Conversion;
  26. import com.opensymphony.xwork2.conversion.annotations.TypeConversion;
  27.  
  28. /**
  29. *
  30. */
  31. @Conversion()
  32. public class IndexAction extends ActionSupport {
  33.  
  34. private Date now = new Date(System.currentTimeMillis());
  35.  
  36. @TypeConversion(converter = "org.teamsmarteat.DateConverter")
  37. public Date getDateNow() { return now; }
  38.  
  39. public String execute() throws Exception {
  40. now = new Date(System.currentTimeMillis());
  41. connectDB();
  42. return SUCCESS;
  43. }
  44.  
  45. private void connectDB () {
  46. String hostName = "smarteat-server.database.windows.net";
  47. String dbName = "smarteatdb";
  48. String user = "lars";
  49. String password = "BananaU24";
  50.  
  51. try {
  52. String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
  53. Class.forName(driver).newInstance();
  54. } catch (ClassNotFoundException e) {
  55. e.printStackTrace();
  56. } catch (IllegalAccessException e) {
  57. e.printStackTrace();
  58. } catch (InstantiationException e) {
  59. e.printStackTrace();
  60. }
  61. String url = String.format("jdbc:sqlserver://%s:1433;database=%s;user=%s;password=%s;encrypt=true;hostNameInCertificate=*.database.windows.net;loginTimeout=30;", hostName, dbName, user, password);
  62. Connection connection = null;
  63.  
  64. try {
  65. connection = DriverManager.getConnection(url);
  66. String schema = connection.getSchema();
  67. System.out.println("Successful connection - Schema: " + schema);
  68. }
  69.  
  70. catch (Exception e) {
  71. e.printStackTrace();
  72. }
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement