Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. package com.bestdist.scrap;
  2.  
  3. import java.sql.*;
  4. import java.util.Properties;
  5.  
  6. import com.jcraft.jsch.JSch;
  7. import com.jcraft.jsch.JSchException;
  8. import com.jcraft.jsch.Session;
  9.  
  10. public class Ezzo11st {
  11.  
  12. private static void doSshTunnel(String strSshUser, String strSshPassword, String strSshHost, int nSshPort,
  13. String strRemoteHost, int nLocalPort, int nRemotePort) throws JSchException {
  14. final JSch jsch = new JSch();
  15. Session session = jsch.getSession(strSshUser, strSshHost, 22);
  16. session.setPassword(strSshPassword);
  17.  
  18. final Properties config = new Properties();
  19. config.put("StrictHostKeyChecking", "no");
  20. session.setConfig(config);
  21.  
  22. session.connect();
  23. session.setPortForwardingL(nLocalPort, strRemoteHost, nRemotePort);
  24. }
  25.  
  26. public static void main(String[] args) {
  27. try {
  28. String strSshHost = "ㅌㅌㅌㅌ.com";
  29. String strSshUser = "ㅌㅌㅌㅌ";
  30. String strSshPassword = "ㅌㅌㅌㅌ";
  31.  
  32. int nSshPort = 22;
  33. String strRemoteHost = "db01.eumshop.com";
  34. int nLocalPort = 3366;
  35. int nRemotePort = 3306;
  36. String strDbUser = "ezzo_mall";
  37. String strDbPassword = "BaLrcMNFbX";
  38.  
  39. Ezzo11st.doSshTunnel(strSshUser, strSshPassword, strSshHost, nSshPort, strRemoteHost, nLocalPort,nRemotePort);
  40.  
  41. Class.forName("com.mysql.jdbc.Driver");
  42. Connection con = DriverManager.getConnection("jdbc:mysql://localhost:"+nLocalPort+"/ezzo_mall", strDbUser, strDbPassword);
  43.  
  44. PreparedStatement pstmt = con.prepareStatement("select * from ADMIN_MENU");
  45. ResultSet rs = pstmt.executeQuery();
  46.  
  47. while(rs.next()) {
  48. System.out.println(rs.getString("AM_NO"));
  49. }
  50. rs.close();
  51. pstmt.close();
  52. con.close();
  53. } catch (Exception e) {
  54. e.printStackTrace();
  55. } finally {
  56. System.exit(0);
  57. }
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement