Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.bestdist.scrap;
- import java.sql.*;
- import java.util.Properties;
- import com.jcraft.jsch.JSch;
- import com.jcraft.jsch.JSchException;
- import com.jcraft.jsch.Session;
- public class Ezzo11st {
- private static void doSshTunnel(String strSshUser, String strSshPassword, String strSshHost, int nSshPort,
- String strRemoteHost, int nLocalPort, int nRemotePort) throws JSchException {
- final JSch jsch = new JSch();
- Session session = jsch.getSession(strSshUser, strSshHost, 22);
- session.setPassword(strSshPassword);
- final Properties config = new Properties();
- config.put("StrictHostKeyChecking", "no");
- session.setConfig(config);
- session.connect();
- session.setPortForwardingL(nLocalPort, strRemoteHost, nRemotePort);
- }
- public static void main(String[] args) {
- try {
- String strSshHost = "ㅌㅌㅌㅌ.com";
- String strSshUser = "ㅌㅌㅌㅌ";
- String strSshPassword = "ㅌㅌㅌㅌ";
- int nSshPort = 22;
- String strRemoteHost = "db01.eumshop.com";
- int nLocalPort = 3366;
- int nRemotePort = 3306;
- String strDbUser = "ezzo_mall";
- String strDbPassword = "BaLrcMNFbX";
- Ezzo11st.doSshTunnel(strSshUser, strSshPassword, strSshHost, nSshPort, strRemoteHost, nLocalPort,nRemotePort);
- Class.forName("com.mysql.jdbc.Driver");
- Connection con = DriverManager.getConnection("jdbc:mysql://localhost:"+nLocalPort+"/ezzo_mall", strDbUser, strDbPassword);
- PreparedStatement pstmt = con.prepareStatement("select * from ADMIN_MENU");
- ResultSet rs = pstmt.executeQuery();
- while(rs.next()) {
- System.out.println(rs.getString("AM_NO"));
- }
- rs.close();
- pstmt.close();
- con.close();
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- System.exit(0);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement