ํŒŒ์ผ๊ณผ ํด๋”๊ฐ€ ๋“ค์–ด์žˆ๋Š” ํด๋” DIR ๊ตฌ์กฐ

[zipDirDownLoad]

๋Œ€์ƒ ํด๋”๋ฅผ ์••์ถ•ํ•ด zip ํŒŒ์ผ๋กœ ์ƒ์„ฑ(compressDir, compressFile)ํ›„, ์ƒ์„ฑํ•œ zip ํŒŒ์ผ์„ response์— ๋‹ด์•„์„œ client์— ๋ณด๋‚ธ๋‹ค.

package com.study.controller;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.io.File;

   /**
    * @param targetDirPath ์••์ถ•ํ•  ํด๋” ๊ฒฝ๋กœ
    * @param outputPath ์ถœ๋ ฅํŒŒ์ผ ๊ฒฝ๋กœ
    * @param outputFileName ์ถœ๋ ฅํŒŒ์ผ๋ช…
    * @description ํด๋” ์••์ถ• ๋ฉ”์†Œ๋“œ
    */
    @SuppressWarnings("resource")
    protected void zipDirDownLoad(HttpServletResponse response, String targetDirPath, String resultPath, String resultFileName) throws Exception {
        // ํŒŒ์ผ๋ช…์— .zip์ด ์—†๋Š” ๊ฒฝ์šฐ, .zip ์„ ๋ถ™์—ฌ์ค€๋‹ค.
        int pos = resultFileName.lastIndexOf(".") == -1 ? resultFileName.length() : resultFileName.lastIndexOf(".");
        if (!resultZipName.substring(pos).equalsIgnoreCase(".zip")) {
            resultFileName += ".zip";
            }
        
        // ์••์ถ• ๋Œ€์ƒ ํŒŒ์ผ ์กด์žฌ ์—ฌ๋ถ€์ฒดํฌ
        File targetDir = new File(targetDirPath);
        if (!targetDir.exists()) {
            response.getWriter().println("<script>alert('File Not Found');history.back();</script>");
            logger.error("TargetDir does not exist.");
            }

        // ํŒŒ์ผ์ถœ๋ ฅ ์ŠคํŠธ๋ฆผ
        FileOutputStream fos = null;
        // ์••์ถ•ํŒŒ์ผ์ถœ๋ ฅ ์ŠคํŠธ๋ฆผ
        ZipOutputStream zos = null;
        try {
            fos = new FileOutputStream(new File(resultPath + resultFileName));  // ํŒŒ์ผ ๊ฐ์ฒด(new File(resultPath + resultFileName))์— ์“ธ ํŒŒ์ผ์ถœ๋ ฅ ์ŠคํŠธ๋ฆผ
            zos = new ZipOutputStream(fos); // zip output stream
            
            // ๋””๋ ‰ํ† ๋ฆฌ ๊ฒ€์ƒ‰๋ฅผ ํ†ตํ•œ ํ•˜์œ„ ํŒŒ์ผ๊ณผ ํด๋” ๊ฒ€์ƒ‰ ๋ฐ ์••์ถ•
            compressDir(targetDir, targetDir.getPath(), zos);
            
            } finally {
                if (zos != null) zos.close();
                if (fos != null) fos.close();
                }
        
        // ์••์ถ• ํŒŒ์ผ์„ response๋กœ ๋ณด๋‚ด๊ธฐ
        File resultZipFile = new File(resultPath + resultFileName);
        FileInputStream fis = new FileInputStream(resultZipFile);
        
        // ํŒŒ์ผ๋ช… ์ธ์ฝ”๋”ฉ ์„ค์ •
        String userAgent = request.getHeader("User-Agent");
        if(userAgent.contains("Edge") || userAgent.contains("MSIE") || userAgent.contains("Trident")) {
            resultZipName = URLEncoder.encode(resultZipName, "UTF-8").replace("\\+", "%20");
        } else if(userAgent.contains("Chrome") || userAgent.contains("Opera") || userAgent.contains("Firefox")) {
            resultZipName = new String(resultZipName.getBytes("UTF-8"), "ISO-8859-1");
        }
        
        byte[] byteFile = new byte[(int) resultZipFile.length()];
        fis.read(byteFile);    // ์ฃผ์–ด์ง„ ๋ฐฐ์—ด byteFile๋งŒํผ์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์ฝ์–ด์„œ byteFile์— ์ €์žฅํ•˜๊ณ  ์ฝ์€ ๋ฐ”์ดํŠธ ์ˆ˜๋ฅผ ๋ฐ˜ํ™˜
        
        response.setContentType("application/zip");
        response.setContentLength(byteFile.length);
        
        response.setHeader("Content-Disposition",  "attachment; filename=\""+resultFileName+"\"");
        response.getOutputStream().write(byteFile); // ์ฃผ์–ด์ง„ ๋ฐฐ์—ด byteFile์— ์ €์žฅ๋œ ๋ชจ๋“  ๋‚ด์šฉ์„ ์ถœ๋ ฅ์†Œ์Šค์— ์“ด๋‹ค.
        
        if(fis != null) fis.close();
        if(resultZipFile.exists()) resultZipFile.delete();
    }

 

[ compressDir ]

๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ํŒŒ์ผ ์ธ์ž๋กœ ๋ฐ›์•„์„œ ๋‚ด์šฉ ํŒŒ์ผ๋“ค์˜ ๋””๋ ‰ํ† ๋ฆฌ์—ฌ๋ถ€์— ๋”ฐ๋ผ ๋ถ„๊ธฐ ์ฒ˜๋ฆฌ

    /**
     * @param file ํ˜„์žฌ ํŒŒ์ผ
     * @param resultRootPath ๋ฃจํŠธ ๊ฒฝ๋กœ
     * @param zos  ์••์ถ• ์ŠคํŠธ๋ฆผ
     * @description ๋””๋ ‰ํ† ๋ฆฌ ํƒ์ƒ‰ ๋ฐ ๋ถ„๊ธฐ
     */
    private void compressDir(File file, String resultRootPath, ZipOutputStream zos) throws Exception {
        // ์ธ์ž๋กœ ์ฃผ์–ด์ง„ ํŒŒ์ผ์ด ๋””๋ ‰ํ† ๋ฆฌ์ธ์ง€ ํŒŒ์ผ์ธ์ง€์— ๋”ฐ๋ผ ๋ถ„๊ธฐ
        if (file.isDirectory()) {
            // ๋””๋ ‰ํ† ๋ฆฌ์ผ ๊ฒฝ์šฐ ์žฌ๊ท€
            File[] files = file.listFiles();
            for (File f : files) {
                compressDir(f, resultRootPath, zos);
                }
            file.delete();
            } else {    // ํŒŒ์ผ์ผ ๊ฒฝ์šฐ ์••์ถ•์„ ํ•œ๋‹ค.
                compressFile(file, resultRootPath, zos);
                }
	}

 

[ compressFile ]

๋ถ„๊ธฐ์ฒ˜๋ฆฌ ์ค‘ ๋””๋ ‰ํ† ๋ฆฌ๊ฐ€ ์•„๋‹Œ ํŒŒ์ผ์ผ ๊ฒฝ์šฐ ์‹ค์งˆ์ ์œผ๋กœ ์••์ถ• ์ˆ˜ํ–‰

    /**
     * @param file ํ˜„์žฌ ํŒŒ์ผ
     * @param resultRootPath ๋ฃจํŠธ ๊ฒฝ๋กœ
     * @param zos  ์••์ถ• ์ŠคํŠธ๋ฆผ
     * @description ํŒŒ์ผ ์••์ถ• ๋ฉ”์„œ๋“œ
     */
    private void compressFile(File file, String resultRootPath, ZipOutputStream zos) throws Exception {
        FileInputStream fis = null;
        try {
            String zipFileName = file.getPath().replace(resultRootPath + "\\", "");
            // ํŒŒ์ผ์„ ์ฝ์–ด๋“ค์ž„
            fis = new FileInputStream(file);
            // Zip์—”ํŠธ๋ฆฌ ์ƒ์„ฑ
            ZipEntry zipentry = new ZipEntry(zipFileName);  // zipFileName์„ ์ด๋ฆ„์œผ๋กœ ๊ฐ€์ง€๋Š” zipEntry ์ƒ์„ฑ
            // ์ŠคํŠธ๋ฆผ์— ๋ฐ€์–ด๋„ฃ๊ธฐ(์ž๋™ ์˜คํ”ˆ)
            zos.putNextEntry(zipentry);         // zip entry๋ฅผ ์“ฐ๊ณ , ์—”ํŠธ๋ฆฌ ๋ฐ์ดํ„ฐ ์‹œ์ž‘์— stream์„ ์œ„์น˜์‹œํ‚ด
            int length = (int) file.length();   // ํŒŒ์ผ์˜ ๊ธธ์ด
            byte[] buffer = new byte[length];   // ํŒŒ์ผ์˜ ๊ธธ์ด๋งŒํผ์˜ ๋ฒ„ํผ
            fis.read(buffer, 0, length);        // ์ตœ๋Œ€ length๊ฐœ์˜ byte๋ฅผ ์ฝ์–ด์„œ, ๋ฐฐ์—ด buffer์˜ ์ง€์ •๋œ ์œ„์น˜(0)๋ถ€ํ„ฐ ์ €์žฅํ•˜๊ณ  ์ฝ์€ ๋ฐ”์ดํŠธ ์ˆ˜ ๋ฐ˜ํ™˜
            zos.write(buffer, 0, length);       // ์ฃผ์–ด์ง„ ๋ฐฐ์—ด buffer์— ์ €์žฅ๋œ ๋‚ด์šฉ ์ค‘์—์„œ 0๋ฒˆ์งธ ๋ถ€ํ„ฐ length๋งŒํผ๋งŒ์„ ์ฝ์–ด์„œ ์ถœ๋ ฅ์†Œ์Šค์— ์“ด๋‹ค.
            zos.closeEntry();                   // ํ˜„์žฌ zip entry๋ฅผ ๋‹ซ๊ณ  ๋‹ค์Œ ์—”ํŠธ๋ฆฌ ์ž‘์„ฑ์„ ์œ„ํ•ด ์œ„์น˜ํ•จ 
            } finally {
                if (fis != null) fis.close();
                if (file != null && file.exists())file.delete();
                }
	}

๋ฐ˜์‘ํ˜•

[๊ฐœ๋ฐœ ํ™˜๊ฒฝ]

์„œ๋ฒ„: Spring Boot 3.2.4

ํ”„๋ก ํŠธ: Vite + React + TypeScript

 

<MyController.java>

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class MyController {

    @RequestMapping(value = "/gnbmenu")
    public String gnbMenu(@RequestBody Object request) {
        String str = "{\"message\" : \"๋ฉ”๋‰ด ์š”์ฒญ url.\"}";
        return str;
    }

}

 

<MyFront.tsx>

import { useEffect } from "react";

function MyFront() {
  const dataToSend = {
    key1: "value1",
    key2: "value2",
  };
  useEffect(() => {
    fetch("/api/gnbmenu", {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify(dataToSend),
    }).then((response) => console.log(response.json()));
  }, []);

  return <></>;
export default MyFront;

 

<Server Console>

2024-04-18T20:10:29.643+09:00 ERROR 26416 --- [****] [nio-8080-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: org.thymeleaf.exceptions.TemplateInputException: Error resolving template [{"message" : "๋ฉ”๋‰ด ์š”์ฒญ url."}], template might not exist or might not be accessible by any of the configured Template Resolvers] with root cause

org.thymeleaf.exceptions.TemplateInputException: Error resolving template [{"message" : "๋ฉ”๋‰ด ์š”์ฒญ url."}], template might not exist or might not be accessible by any of the configured Template Resolvers
	at org.thymeleaf.engine.TemplateManager.resolveTemplate(TemplateManager.java:869) ~[thymeleaf-3.1.2.RELEASE.jar:3.1.2.RELEASE]
	at org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:607) ~[thymeleaf-3.1.2.RELEASE.jar:3.1.2.RELEASE]
	at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1103) ~[thymeleaf-3.1.2.RELEASE.jar:3.1.2.RELEASE]
	at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1077) ~[thymeleaf-3.1.2.RELEASE.jar:3.1.2.RELEASE]
	at org.thymeleaf.spring6.view.ThymeleafView.renderFragment(ThymeleafView.java:372) ~[thymeleaf-spring6-3.1.2.RELEASE.jar:3.1.2.RELEASE]
	at org.thymeleaf.spring6.view.ThymeleafView.render(ThymeleafView.java:192) ~[thymeleaf-spring6-3.1.2.RELEASE.jar:3.1.2.RELEASE]
	at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1431) ~[spring-webmvc-6.1.5.jar:6.1.5]
	at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1167) ~[spring-webmvc-6.1.5.jar:6.1.5]
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1106) ~[spring-webmvc-6.1.5.jar:6.1.5]
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:979) ~[spring-webmvc-6.1.5.jar:6.1.5]
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1014) ~[spring-webmvc-6.1.5.jar:6.1.5]
	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:914) ~[spring-webmvc-6.1.5.jar:6.1.5]
	at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:590) ~[tomcat-embed-core-10.1.19.jar:6.0]
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:885) ~[spring-webmvc-6.1.5.jar:6.1.5]
	at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:658) ~[tomcat-embed-core-10.1.19.jar:6.0]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:205) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51) ~[tomcat-embed-websocket-10.1.19.jar:10.1.19]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
	at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) ~[spring-web-6.1.5.jar:6.1.5]
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) ~[spring-web-6.1.5.jar:6.1.5]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
	at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) ~[spring-web-6.1.5.jar:6.1.5]
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) ~[spring-web-6.1.5.jar:6.1.5]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) ~[spring-web-6.1.5.jar:6.1.5]
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) ~[spring-web-6.1.5.jar:6.1.5]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:167) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:90) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:482) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:115) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:93) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:344) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:391) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:896) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1744) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
	at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
	at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:63) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
	at java.base/java.lang.Thread.run(Thread.java:842) ~[na:na]

 

<Client console>

MyFront.tsx:36 
 POST http://localhost:5173/api/gnbmenu 500 (Internal Server Error)
(anonymous)	@	MyFront.tsx:36
Show 10 more frames

 

[์˜ˆ์ƒ ๋ฌธ์ œ 1]

๊ฒฝ๋กœ ์„ค์ • ๋ฌธ์ œ?

"/abc"๋กœ ์‹œ์ž‘ํ•˜๋Š” ๊ฒฝ๋กœ์—์„œ "/"์„ ์ œ๊ฑฐํ•˜๊ณ  "abc"ํ˜•ํƒœ๋กœ ์ˆ˜์ • โ˜ž AWS๋‚˜ ๋ฐฐํฌ ํ™˜๊ฒฝ์—์„œ ๋ฐœ์ƒํ•˜๋Š” ๋ฌธ์ œ๋กœ ํ•ด๋‹น ๋ฌธ์ œ๊ฐ€ ์•„๋‹˜

 

[๋ฌธ์ œ 2]

Controller Annotaion ์ข…๋ฅ˜์˜ ๋ฌธ์ œ

@Controller๋Š” ๋ฐ˜ํ™˜๊ฐ’์œผ๋กœ view๋ฅผ ์ฐพ์Œ. view๊ฐ€ ์•„๋‹Œ jsonํ˜•ํƒœ๋ฅผ ๋ฐ˜ํ™˜ํ•˜๊ธฐ ๋•Œ๋ฌธ์— @RestController๋กœ ์„ค์ • โ˜ž ํ•ด๊ฒฐ

 

๋ฐ˜์‘ํ˜•
package com.study.controller;

import org.apach.commons.io.FileUtils;
import org.springFamework.http.HttpHeaders;
import org.springFamework.http.HttpStatus;
import org.springFamework.http.MediaType;
import org.springFamework.http.ResponseEntity;


@Controller
public class AttachFileController {

	@RequestMapping("/pdfView")
    public ResponseEntity<byte[]> pdfView(HttpServletRequest request, HttpServletResponse) throws Exception{
    	request.setCharacterEncoding("utf-8");
        String fileId = new String(request.getParameter("fileId".getBytes("8859_1", "KSC5601");
        // fileId ์—†๋Š” ๊ฒฝ์šฐ ์˜ˆ์™ธ์ฒ˜๋ฆฌ
        // fileId์— ํ•ด๋‹นํ•˜๋Š” ํŒŒ์ผ ์—†๋Š” ๊ฒฝ์šฐ ์˜ˆ์™ธ์ฒ˜๋ฆฌ
              
        String filePath = ${FILES_ROOT_PATH} + fileId;
        String tempFile = new File(filePath);
        byte[] pdfBytes;
        
        try {
        	pdfBytes = org.apache.commons.io.FileUtils.readFileToByteArray(tempFile);
        } catch (Exception e){
        	e.printStackTrace();
            String error = "<script tye='text/javascript'> alert('File Not Found');</script>";
            byte[] arrorBytes = error.getBytes(StandardCharsets.UTF_8);
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorBytes);
            }
            
        HttpHeaders = headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_PDF);
        headers.setContentDispositionFormData("filename", "example.pdf");
        headers.setContentLength(pdfBytes.length);
        //ํŒŒ์ผ์ด ๋‹ค์šด๋กœ๋“œ ๋˜์ง€ ์•Š๊ณ  ๋ธŒ๋ผ์šฐ์ € ๋‚ด์— ๋ณด์ด๋„๋ก ํ•จ
        headers.set("Content-Disposition", "inline; filename=example.pdf"
        
        return new ResponseEntity<>(pdfBytes, headers, HttpStatus.OK);
    }

}
๋ฐ˜์‘ํ˜•

Oracle DataBase๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ์„ค์น˜๋˜์—ˆ๊ณ  ์‹คํ–‰๊นŒ์ง€ ํ™•์ธ ํ–ˆ๋‹ค.

์ด์ œ ํ”„๋กœ์ ํŠธ์— ์—ฐ๋™ ํ•  ํ…Œ์ด๋ธ” ์ŠคํŽ˜์ด์Šค, ์‚ฌ์šฉ์ž๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ์—ฐ๋™ํ•˜๋ฉด ๋œ๋‹ค.

 

1. ํ…Œ์ด๋ธ” ์ŠคํŽ˜์ด์Šค์™€ ์‚ฌ์šฉ์ž ์ƒ์„ฑ

2. SQL Developer๋กœ ์ ‘์† ํ™•์ธ

3. ํ”„๋กœ์ ํŠธ ๋‚ด์— ์„ค์ • ๋ณ€๊ฒฝ


1. ํ…Œ์ด๋ธ” ์ŠคํŽ˜์ด์Šค์™€ ์‚ฌ์šฉ์ž ์ƒ์„ฑ

๋”๋ณด๊ธฐ

1. (root ๊ถŒํ•œ์œผ๋กœ ๋ณ€๊ฒฝ ํ›„) ํ…Œ์ด๋ธ” ์ŠคํŽ˜์ด์Šค ๋ฐ์ดํ„ฐ๋ฅผ ๋ณด๊ด€ํ•  ๋””๋ ‰ํ† ๋ฆฌ ์ƒ์„ฑ ex) /home/oracle/data

# mkdir /home/oracle/data

2. ๋””๋ ‰ํ† ๋ฆฌ์˜ ๊ถŒํ•œ ๋ณ€๊ฒฝ

#sudo chmod 777 /home/oracle/data

3. ์˜ค๋ผํด ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์‹คํ–‰

# sqlplus

 4. ๊ด€๋ฆฌ์ž๋กœ ๋กœ๊ทธ์ธ (user-name : sys as sysdba | ๋น„๋ฐ€๋ฒˆํ˜ธ๋Š” ์„ค์ • ์ ์šฉ ์‹œ ์ž…๋ ฅํ–ˆ๋˜ ๋น„๋ฐ€๋ฒˆํ˜ธ ex. 12345)

Enter user-name: sys as sysdba
Enter password: 12345

4. ํ…Œ์ด๋ธ” ์ŠคํŽ˜์ด์Šค ์ƒ์„ฑ ex

SQL> create tablespace test datafile '/home/oracle/data/test.dbf' size 500m autoextend on next 100m maxsize unlimited default storage(initial 128k next 64k pctincrease 10);

 5. ์„ธ์…˜ ๋ชจ๋“œ ๋ณ€๊ฒฝ

SQL> alter session set "_ORACLE_SCRIPT" = true;

6. ์‚ฌ์šฉ์ž ์ƒ์„ฑ ๋ฐ ํ…Œ์ด๋ธ” ์ŠคํŽ˜์ด์Šค ์ง€์ •

SQL> create user testuser identified by "12345" default tablespace test temporary tablespace temp;

7. ์‚ฌ์šฉ์ž์—๊ฒŒ ๊ถŒํ•œ ๋ถ€์—ฌ

SQL> grant resource, connect, dba to testuser;

2. SQL Developer๋กœ ์ ‘์† ํ™•์ธ

๋”๋ณด๊ธฐ

 1. SQL Developer์‹คํ–‰ ํ›„ ์ˆ˜๋™์œผ๋กœ ์ ‘์† ์ƒ์„ฑ ์„ ํƒ

2. ์ ‘์† ์ •๋ณด ์ž…๋ ฅ

- Name : ์ ‘์†์„ ์‹๋ณ„ํ•  ์ˆ˜ ์žˆ๋Š” ์ด๋ฆ„

- ์‚ฌ์šฉ์ž ์ด๋ฆ„, ๋น„๋ฐ€๋ฒˆํ˜ธ  : OracleDatabase์—์„œ ์ƒ์„ฑํ–ˆ๋˜ ์‚ฌ์šฉ์ž ์ด๋ฆ„(ex.testuser)๊ณผ ๋น„๋ฐ€๋ฒˆํ˜ธ(12345)

SQL> create user testuser identified by "12345" default tablespace test temporary tablespace temp;

- ํ˜ธ์ŠคํŠธ ์ด๋ฆ„ : ์ธ์Šคํ„ด์Šค์˜ ์™ธ๋ถ€(๊ณต๊ณต, public) ip

- ํฌํŠธ : ์˜ค๋ผํด ์‹คํ–‰ ์ „ ์ ์šฉํ•œ ์„ค์ • ํŒŒ์ผ์˜ ๋‚ด์šฉ ๋Œ€๋กœ(๊ธฐ๋ณธ 1521)

- SID : XE

 

3. ํ…Œ์ŠคํŠธ ํ›„ '์ƒํƒœ:์„ฑ๊ณต' ํ™•์ธ

 ์ ‘์†์ด ๋˜์ง€ ์•Š์„ ๊ฒฝ์šฐ ์ธ์Šคํ„ด์Šค์˜ 1521ํฌํŠธ์— ๋Œ€ํ•œ ์ธ๋ฐ”์šด๋“œ ๊ทœ์น™์„ ์ˆ˜์ •ํ•ด์„œ ํ—ˆ์šฉ ํ•ด์ค˜์•ผ ํ•œ๋‹ค.

(๋ณด์•ˆ์ƒ ์ด๋ ‡๊ฒŒ ์™ธ๋ถ€์—์„œ ์ ‘์†์€ ํ—ˆ์šฉํ•˜์ง€ ์•Š๋Š” ๊ฒƒ์ด ๋งž๊ณ  ์—ฐ๋™ ์‹œ์—๋„ ๋‚ด๋ถ€ ํ†ต์‹ ์œผ๋กœ ํ•ด์•ผ ํ•˜์ง€๋งŒ ์•„์ง ์ดํ•ด ํ•ด์•ผ ํ•  ๋ถ€๋ถ„์ด ๋งŽ์•„์„œ ์šฐ์„  ์ด๋ ‡๊ฒŒ ์ง„ํ–‰ ํ•จ)


์ด๋ ‡๊ฒŒ ํ•œ ํ›„ SQL Developer๋กœ ์ž‘์—…์„ ํ•  ์ˆ˜ ๋„ ์žˆ๊ณ , ๋‚˜์˜ ํŒ€ ํ”„๋กœ์ ํŠธ์—์„œ๋Š” jpa๋ฅผ ์‚ฌ์šฉํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— ํ”„๋กœ์ ํŠธ์— ์—ฐ๋™ ํ›„ ์ •์ƒ์ ์œผ๋กœ ํ…Œ์ด๋ธ” ๋“ฑ์ด ์ƒ์„ฑ ๋˜๋Š”์ง€ ํ™•์ธํ–ˆ๋‹ค.

 


3. ํ”„๋กœ์ ํŠธ์— ์—ฐ๋™

๋”๋ณด๊ธฐ

ํ”„๋กœ์ ํŠธ์˜ application.properties ํŒŒ์ผ๋‚ด์—์„œ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ˆ˜์ • ํ•ด ์ค€ ๋’ค jar ํŒŒ์ผ์„ ์ƒ์„ฑ ํ–ˆ๋‹ค.

์ƒ์„ฑํ•œ ํŒŒ์ผ์„ ๋กœ์ปฌ ๋˜๋Š” ํด๋ผ์šฐ๋“œ ํ™˜๊ฒฝ์—์„œ ์‹คํ–‰ ์‹œํ‚ค๋ฉด (๋‚˜์˜ ๊ฒฝ์šฐ aws ec2 ์ด์šฉ)

์ด๋ ‡๊ฒŒ ๋กœ๊ทธ๋กœ Hibernate์˜ SQL๋กœ ์ •์ƒ ์ž‘๋™๋˜๋Š” ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ๊ณ ,

SQL Developer๋กœ๋„ ํ…Œ์ด๋ธ”์ด ์ •์ƒ์ ์œผ๋กœ ์ƒ์„ฑ๋œ ๊ฒƒ์„ ํ™•์ธ ํ•  ์ˆ˜ ์žˆ๋‹ค.

 


๋„ˆ๋ฌด ๊ฐ๊ฒฉ์Šค๋Ÿฌ์›Œ์„œ ์ด๋ ‡๊ฒŒ๋ผ๋„ ํ•œ๋ฒˆ ์ •๋ฆฌ๋ฅผ ํ•ด๋‘๊ณ  ์‹ถ์—ˆ๋‹ค.

๋ณด์•ˆ๋ฌธ์ œ๋‚˜ ์—ฌ๋Ÿฌ๊ฐ€์ง€ ๋” ์•Œ์•„๊ฐ€์•ผ ํ•  ๊ฒƒ์ด ๋งŽ์ง€๋งŒ ์—ญ์‹œ ๊ดด๋กญ์ง€๋งŒ ์žฌ๋ฐŒ๋‹ค..ใ…Žใ…Ž

 

์ •ํ™•ํ•˜๊ฒŒ ๋ผ์ด์„ผ์Šค ๋ถ€๋ถ„์— ๋Œ€ํ•ด์„œ ์–ด๋–ค์ง€ ๋ชจ๋ฅด๊ฒ .. ๋Š”๋ฐ ํ•ด๋ณด๋Š” ์ˆ˜์ค€์—์„œ๋Š” ๊ดœ์ฐฎ์ง€ ์•Š์„๊นŒ ํ•ด์„œ ๊ธฐ๋ก์œผ๋กœ ๋‚จ๊น€!

๋ช‡๊ฐ€์ง€๋งŒ ํ…Œ์ŠคํŠธ ํ•œ ํ›„์— ํ…Œ์ŠคํŠธ์— ์‚ฌ์šฉ ํ•œ ์ธ์Šคํ„ด์Šค๋“ค์€ ๋ชจ๋‘ ์‚ญ์ œํ–ˆ์œผ๋‹ˆ๊นŒ ์˜ค๋ผํด์—์„œ ์ฒ ์ปน์ฒ ์ปน ํ•˜์ง„ ์•Š๊ฒ ์ง€..?๐Ÿฅบ

 

 

 

 

 

 

 

+ ์‚ฌ์šฉ ๋น„์šฉ ์ˆ˜์ค€ ๊ด€๋ จ

๋”๋ณด๊ธฐ

์ด๋ ‡๊ฒŒ ๋ช‡๋ฒˆ ์ธ์Šคํ„ด์Šค ์ƒ์„ฑํ•˜๊ณ  ์‚ญ์ œํ•˜๊ณ  ์—ฐ์Šตํ•˜๊ณ  ํ•˜๋Š”๋™์•ˆ

์‚ฌ์šฉ๋œ ํฌ๋ ˆ๋”ง์€ 7์ฒœ์› ๊ฐ€๋Ÿ‰์ด๋‹ˆ๊นŒ ๋‚จ์€ ๊ธฐ๊ฐ„๋™์•ˆ ๋” ๋งŽ์ด ์—ฐ์Šตํ•˜๊ณ  ํ…Œ์ŠคํŠธ ํ•ด๋ด์•ผ๊ฒ ๋‹ค!

์ผ๋ถ€๋Ÿฌ ์„ฑ๋Šฅ ๋„‰๋„‰ํ•œ๊ฒƒ์œผ๋กœ ์ƒ์„ฑํ•ด์„œ ์‚ฌ์šฉํ–ˆ๋Š”๋ฐ ์ด์ •๋„๋‹ˆ๊นŒ AWS ๋ณด๋‹ค ์—ฌ๋Ÿฌ๊ฐ€์ง€ ์‹œ๋„ ํ•ด๋ณด๊ธฐ๋Š” ๋” ์ข‹์€๊ฒƒ ๊ฐ™๋‹ค.

(AWS๋Š” ์ผ์ • ์„ฑ๋Šฅ์„ ๋„˜๊ฑฐ๋‚˜ ํ•ด๋ฒ„๋ฆฌ๋ฉด ๊ณผ๊ธˆ์ด ๋˜๊ณ  ์ˆ˜์ฒœ๋งŒ์›์”ฉ ์ฒญ๊ตฌ๋๋‹ค๋Š” ๊ดด๋‹ด๋„ ๋“ค๋ ค์„œ ์ชผ๊ธˆ ๋ฌด์„ญ๊ธฐ๋„ ํ–ˆ์Œ)

 

 

๋ฐ˜์‘ํ˜•

์•ž์˜ ๊ณผ์ •์„ ํ†ตํ•ด VM ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ–ˆ๊ณ  ๋‹ค์Œ์œผ๋กœ ์‹ค์ œ ์„ค์น˜๋ฅผ ์ง„ํ–‰ํ•œ๋‹ค.

์„ค์น˜ ํŒŒ์ผ์„ ์˜ฎ๊ธด ํ›„ ๋ถ€ํ„ฐ๋Š” ์˜ค๋ผํด ๊ณต์‹ ํ™ˆํŽ˜์ด์ง€์— ๋‚˜์˜จ๋Œ€๋กœ๋งŒ ๋”ฐ๋ผํ•˜๋ฉด ๋œ๋‹ค.

 

1) FileZilla๋ฅผ ์ด์šฉํ•ด vm ์ธ์Šคํ„ด์Šค์— ์„ค์น˜ํŒŒ์ผ ์˜ฎ๊ธฐ๊ธฐ

2) VM ์ธ์Šคํ„ด์Šค ๋‚ด์—์„œ ์„ค์น˜ ์ง„ํ–‰ํ•˜๊ธฐ


1) FileZilla๋ฅผ ์ด์šฉํ•ด vm ์ธ์Šคํ„ด์Šค์— ์„ค์น˜ํŒŒ์ผ ์˜ฎ๊ธฐ๊ธฐ

๋”๋ณด๊ธฐ

1. FileZilla ํ”„๋กœ๊ทธ๋žจ์„ ์‹คํ–‰ํ•˜๊ณ  VM ์ธ์Šคํ„ด์Šค์™€ ์—ฐ๊ฒฐ์„ ์„ค์ •ํ•œ๋‹ค.

โ‘  FileZilla ํ”„๋กœ๊ทธ๋žจ์˜ ์ƒ๋‹จ ํŒŒ์ผ → ์‚ฌ์ดํŠธ ๊ด€๋ฆฌ์ž ๋ฉ”๋‰ด์— ๋“ค์–ด๊ฐ„๋‹ค

โ‘ก ์ƒˆ์‚ฌ์ดํŠธ → ์—ฐ๊ฒฐ์„ ๊ตฌ๋ถ„ํ•  ์ˆ˜ ์žˆ๋Š” ์ด๋ฆ„(๋˜๋Š” ๊ทธ๋ƒฅ ์ƒˆ์‚ฌ์ดํŠธ์—ฌ๋„ ์ƒ๊ด€ X) → ์—ฐ๊ฒฐ์„ ์œ„ํ•œ ๊ฐ’ ์ž…๋ ฅ

โ‘ก-1 ์ผ๋ฐ˜ ์„ค์ • ๋‚ด์šฉ 

  • ํ”„๋กœํ† ์ฝœ : SFTP - SSH File Transfer Protocol
  • ํ˜ธ์ŠคํŠธ : <์ธ์Šคํ„ด์Šค์˜ public ip(external ip)>
    • ์•ž์„œ ํ™•์ธํ–ˆ๋˜ GCP VM์ธ์Šคํ„ด์Šค์˜ ์™ธ๋ถ€ ip
  • ํฌํŠธ : (๊ณต๋ž€)
  • ๋กœ๊ทธ์˜จ ์œ ํ˜• : ํ‚คํŒŒ์ผ
  • ์‚ฌ์šฉ์ž : <Key comment>
    • PuTTY๋กœ SSHํ‚ค ์ƒ์„ฑ ์‹œ ์•Œ์•„ ๋‘์—ˆ๋˜ Key comment 

โ‘ก-2. ์„ค์ • ํ›„ ํ‚คํŒŒ์ผ ์˜†์˜ ์ฐพ์•„๋ณด๊ธฐ→ PuTTY๋กœ SSHํ‚ค ์ƒ์„ฑ ์‹œ ์ €์žฅํ•ด ๋‘์—ˆ๋˜ Private key ํŒŒ์ผ ์„ ํƒ

โ‘ข ์—ฐ๊ฒฐ→ ํ™•์ธ

โ‘ฃ ์—ฐ๊ฒฐ์ด ์ •์ƒ์ ์œผ๋กœ ๋˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด vm instance์— ์ ‘์† ๋œ ๋ชจ์Šต์ด ๋ณด์ธ๋‹ค.

2. Oracle Database ์„ค์น˜ ํŒŒ์ผ์„ ์ „์†กํ•œ๋‹ค.

์•ž์„œ ๋‹ค์šด๋กœ๋“œ ํ•ด๋‘์—ˆ๋˜ Oracle21cXE ์„ค์น˜ ํŒŒ์ผ์„ drag&drop์œผ๋กœ ๊ฐ€์ ธ๋‹ค ๋†“์œผ๋ฉด ์ „์†ก์ด ์‹œ์ž‘๋œ๋‹ค.

(์šฉ๋Ÿ‰์ด ํฌ๊ณ  ์ตœ๋Œ€ ์†๋„๊ฐ€ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— 10๋ถ„ ๊ฐ€๋Ÿ‰ ์†Œ์š”๋์Œ)

์ „์†ก์ด ์™„๋ฃŒ ๋œ ํ›„ ์ธ์Šคํ„ด์Šค์— ํŒŒ์ผ์ด ๋“ค์–ด๊ฐ„ ๊ฒƒ์„ ํ™•์ธ ํ•  ์ˆ˜ ์žˆ๋‹ค.

2) VM ์ธ์Šคํ„ด์Šค ๋‚ด์—์„œ Oracle21cXE ์„ค์น˜ ์ง„ํ–‰ํ•˜๊ธฐ

2-1) SSH๋กœ ์ธ์Šคํ„ด์Šค์— ์ ‘์†ํ•˜๊ธฐ

๋”๋ณด๊ธฐ

    vm ์ธ์Šคํ„ด์Šค์— ์ ‘์†ํ•˜๊ธฐ ์œ„ํ•ด์„œ GCP์—์„œ ์ œ๊ณตํ•˜๋Š” SSH๋ฅผ ์ด์šฉํ•˜๊ฑฐ๋‚˜ XShell ๋“ฑ ํŽธํ•œ ๋ฐฉ๋ฒ•์œผ๋กœ ์ ‘์†ํ•˜๋ฉด ๋œ๋‹ค.

(GCP์—์„œ ์ œ๊ณตํ•˜๋Š” SSH๋Š” ๋ฐ”๋กœ ์ด์šฉํ•  ์ˆ˜ ์žˆ๊ณ  ์™ธ๋ถ€์˜ ํ”„๋กœ๊ทธ๋žจ์„ ์ด์šฉํ•˜๋ฉด FileZilla์—์„œ ์ ‘์†ํ–ˆ๋˜๊ฒƒ๊ณผ ๊ฐ™์€ ๋ฐฉ๋ฒ•์œผ๋กœ ์„ค์ • ํ›„ ์ ‘์† ํ•  ์ˆ˜ ์žˆ๋‹ค.)

๋‚˜๋Š” GCP์—์„œ ์ œ๊ณตํ•˜๋Š” SSH๋ฅผ ์ด์šฉํ–ˆ๋‹ค. GCP์˜ ์ธ์Šคํ„ด์Šค ๋ชฉ๋ก์—์„œ ์ ‘์† ๊ฐ€๋Šฅํ•˜๋‹ค.

 SSH๋ฅผ ๋ˆ„๋ฅด๊ณ  ์ž ๊น์˜ ์‹œ๊ฐ„์ด ํ๋ฅธ ๋’ค ์ •์ƒ์ ์œผ๋กœ ์ ‘์† ๋˜๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด ํ„ฐ๋ฏธ๋„์ด ๋œฌ๋‹ค.

2-2) Oracle21cXE ์„ค์น˜ ์ง„ํ–‰ 

๋”๋ณด๊ธฐ

 ์ดํ›„ ๋ถ€ํ„ฐ๋Š” ์˜ค๋ผํด ๊ณต์‹ ํ™ˆํŽ˜์ด์ง€์˜ ๋ฌธ์„œ๋Œ€๋กœ๋งŒ ํ•˜๋ฉด ๋œ๋‹ค.

https://docs.oracle.com/en/database/oracle/oracle-database/21/xeinl/installing-oracle-database-free.html#GUID-728E4F0A-DBD1-43B1-9837-C6A460432733

 

Installation Guide

You can install Oracle Database Express Edition using RPM packages.

docs.oracle.com

 ๊ฐ„๋‹จํ•˜๊ฒŒ ์ •๋ฆฌ ํ•ด๋ณด์ž๋ฉด

 

1. ๋ณธ ํ”„๋กœ๊ทธ๋žจ ์„ค์น˜ ์ „ Preinstallation RPM ์„ค์น˜

    1) ๊ด€๋ฆฌ์ž ๊ถŒํ•œ์œผ๋กœ ๋ณ€๊ฒฝ

$ sudo -s

   2) Preinstallation RPM ๊ตฌ๋™ ๊ฐ ์šด์˜์ฒด์ œ์™€ ๋ฒ„์ „ ๋ณ„๋กœ ๋ช…๋ น์–ด๊ฐ€ ๋‹ค๋ฆ„

        (๋‚˜๋Š” RHEL์„ ๊ฐ€์ ธ๋‹ค ๋งŒ๋“  centOS7์„ ์ผ๊ธฐ ๋•Œ๋ฌธ์— b-1์˜ ๋ช…๋ น์–ด ์‚ฌ์šฉ)

 

      a. ์šด์˜์ œ์ œ๊ฐ€ Oracle Linux(OL)์ธ ๊ฒฝ์šฐ

          a-1. Oracle Linux 8 (OL 8)

# dnf -y install oracle-database-preinstall-21c

          a-2. Oracle Linux 7 (OL 7)

# yum -y install oracle-database-preinstall-21c

      b. ์šด์˜์ฒด์ œ๊ฐ€ Red Hat Enterprise Linux(RHEL)์ธ ๊ฒฝ์šฐ

          b-1. Red Hat Enterprise Linux 7

# curl -o oracle-database-preinstall-21c-1.0-1.el7.x86_64.rpm https://yum.oracle.com/repo/OracleLinux/OL7/latest/x86_64/getPackage/oracle-database-preinstall-21c-1.0-1.el7.x86_64.rpm
# yum -y localinstall oracle-database-preinstall-21c-1.0-1.el7.x86_64.rpm

          b-2. Red Hat Enterprise Linux 8

# curl -o oracle-database-preinstall-21c-1.0-1.el8.x86_64.rpm https://yum.oracle.com/repo/OracleLinux/OL8/appstream/x86_64/getPackage/oracle-database-preinstall-21c-1.0-1.el8.x86_64.rpm
# dnf -y localinstall oracle-database-preinstall-21c-1.0-1.el8.x86_64.rpm

2. ์•„๊นŒ ์ „์†กํ•ด ๋‘” Oracle 21cXE ์„ค์น˜ ํŒŒ์ผ๋กœ ์„ค์น˜ ์ง„ํ–‰

- ์ „์†ก๋œ ํŒŒ์ผ์„ ๋ณต์‚ฌํ•˜๊ฑฐ๋‚˜ ์ด๋™ ํ›„ ์„ค์น˜ ํŒŒ์ผ์ด ์žˆ๋Š” ๊ฒฝ๋กœ์—์„œ ๋‹ค์Œ ๋ช…๋ น์–ด ์‹คํ–‰

   (๋‚˜๋Š” ๋‚˜์˜ ๊ณ„์ •์— oracle์ด๋ผ๋Š” ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ์ „์†กํ•ด๋‘์—ˆ๋˜ ํŒŒ์ผ์„ ๋ณต์‚ฌํ•ด์„œ ์„ค์น˜ ์ง„ํ–‰)

 

    For Oracle Linux 7 ๋˜๋Š” Red Hat Enterprise Linux 7 :

# yum -y localinstall oracle-database-xe-21c-1.0-1.ol7.x86_64.rpm

    For Oracle Linux 8 ๋˜๋Š” Red Hat Enterprise Linux 8 :

# dnf -y localinstall oracle-database-xe-21c-1.0-1.ol8.x86_64.rpm
์ด๋ ‡๊ฒŒ complete!๊ฐ€ ๋œจ๋ฉด ์„ค์น˜๊ฐ€ ์™„๋ฃŒ ๋œ๊ฒƒ

3.์‹คํ–‰์ „ ํ•„์š” ์„ค์ • ๋ฐ ์ ์šฉ

OracleDatabase ์‹คํ–‰์— ํ•„์š”ํ•œ ์„ค์ •๋“ค์€ /etc/sysconfig/oracle—xe–21c.conf ํŒŒ์ผ์—์„œ ์ˆ˜์ • ํ•  ์ˆ˜ ์žˆ๋‹ค.

๋‚˜๋Š” ๊ทธ๋ƒฅ ๊ธฐ๋ณธ์œผ๋กœ ๋˜์–ด ์žˆ๋Š” ์„ค์ • ํŒŒ์ผ์„ ์ ์šฉํ–ˆ๋‹ค. ๋‹ค์Œ ๋ช…๋ น์–ด๋กœ ์„ค์ • ํŒŒ์ผ์„ ์ ์šฉํ•œ๋‹ค.

(๊ธฐ๋ณธ ์„ค์ •๋‚ด์šฉ์€ ์ปจํ…Œ์ด๋„ˆ DB (XE)์— XEPDB1 ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ์ƒ์„ฑํ•˜๊ณ 

  ์ ‘์† ํฌํŠธ 1521, Enterprise Manager Express์˜ ํฌํŠธ 5500์œผ๋กœ ์„ค์ • ๋œ๋‹ค.)

# /etc/init.d/oracle-xe-21c configure

์„ค์ • ํŒŒ์ผ์ด ์‹คํ–‰๋˜๋ฉด์„œ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์„ค์ •ํ•˜๋„๋ก ํ•˜๋Š” line์ด ๋œจ๋ฉด ๊ด€๋ฆฌ์ž ๊ถŒํ•œ์œผ๋กœ ์ ‘์†ํ•  ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•˜๊ณ ๋‚˜๋ฉด ํ•œ๋ฒˆ๋” ํ™•์ธ์œผ๋กœ ์ž…๋ ฅํ•œ๋‹ค.

๊ทธ๋ฆฌ๊ณ  ์‹œ๊ฐ„์ด ์ข€ ์ง€๋‚œ ๋’ค ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์„ค์น˜๊ฐ€ ์™„๋ฃŒ ๋œ๋‹ค.

2-3) ํ™˜๊ฒฝ ๋ณ€์ˆ˜ ์„ค์ •

๋”๋ณด๊ธฐ

์œ„์˜ ๋ฐฉ๋ฒ•์œผ๋กœ ์„ค์น˜๋ฅผ ์™„๋ฃŒํ–ˆ๊ณ  sqlplus ๋ช…๋ น์œผ๋กœ ์‹คํ–‰ํ•˜๊ธฐ ์œ„ํ•ด ๋ช‡๊ฐ€์ง€ ํ™˜๊ฒฝ๋ณ€์ˆ˜๋ฅผ ์„ค์ • ํ•ด ์ฃผ์–ด์•ผ ํ•œ๋‹ค.

(์ด ๋‚ด์šฉ์€ ์ž„์‹œ๋กœ ์‚ฌ์šฉ ๊ฐ€๋Šฅ ํ–ˆ๋Š”๋ฐ,

์ž์„ธํ•œ ๋‚ด์šฉ์„ ๋‹ค์‹œ ์ฐพ๊ฑฐ๋‚˜ ์ •๋ฆฌํ•˜์ง€ ๋ชปํ•ด์„œ ์šฐ์„  ๋‚ด๊ฐ€ ์‚ฌ์šฉํ–ˆ๋˜ ๋ฐฉ๋ฒ•์„ ์จ๋‘”๋‹ค.)

 

โ‘  ํ™˜๊ฒฝ๋ณ€์ˆ˜ ์„ค์ • ํŒŒ์ผ์„ ํŽธ์ง‘ํ•˜๊ธฐ ์œ„ํ•ด vim ์—๋””ํ„ฐ๋กœ ํŒŒ์ผ์„ ์—ฐ๋‹ค.

# vi ~/.bash_profile

โ‘ก ๊ธฐ์กด ๋‚ด์šฉ ํ•˜๋‹จ์— ๋‹ค์Œ ๋‚ด์šฉ์„ ์ถ”๊ฐ€ ํ›„ ์ €์žฅ>๋‹ซ๊ธฐ

export ORACLE_HOME=<your_oracle_home>
export ORACLE_SID=<your_oracle_sid>
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH

 โ€ป ๋‚ด๊ฐ€ ์‚ฌ์šฉํ•œ ํ™˜๊ฒฝ๋ณ€์ˆ˜ ์„ค์ • ํŒŒ์ผ(/.bash_profile)์˜ ๋‚ด์šฉ์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/.local/bin:$HOME/bin

export PATH

#Oracle env setting#Oracle env setting
export ORACLE_HOME=/opt/oracle/product/21c/dbhomeXE
export ORACLE_SID=XE
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH

export ORACLE_HOME=/opt/oracle/product/21c/dbhomeXE
export ORACLE_SID=XE
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH

โ‘ข ์„ค์ •ํ•œ ํ™˜๊ฒฝ๋ณ€์ˆ˜ ์ ์šฉ ํ›„ ํ™•์ธ

# source ~/.bash_profile
# env

โ‘ฃ OracleDatabase ์‹คํ–‰

# sqlplus

    ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์‚ฌ์šฉ์ž๋ช…์„ ์ž…๋ ฅํ•˜๋ผ๋Š” ๋‚ด์šฉ์ด ๋‚˜์˜ค๋ฉด ์ •์ƒ์ ์œผ๋กœ ์„ค์ • ๋œ๊ฒƒ์ด๋‹ค.


 

์ด์ œ๋ถ€ํ„ฐ๋Š” ์ด์ „์— ํ–ˆ๋˜๊ฒƒ๊ณผ ๊ฐ™์ด ํ…Œ์ด๋ธ” ์ŠคํŽ˜์ด์Šค๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ์‚ฌ์šฉ์ž๋ฅผ ์ƒ์„ฑํ•˜๋ฉด ๋œ๋‹ค.

๋ฐ˜์‘ํ˜•

๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ํด๋ผ์šฐ๋“œ ํ™˜๊ฒฝ์—์„œ ์šด์˜ํ•˜๋Š” ์—ฌ๋Ÿฌ๊ฐ€์ง€ ๋ฐฉ๋ฒ•์ด ์žˆ๋‹ค.

AWS์˜ RDS๊ฐ€ ๊ฐ€์žฅ ํŽธํ•œ ๋ฐฉ๋ฒ•์ด์—ˆ์ง€๋งŒ OracleDB์˜ ๊ฒฝ์šฐ ๋ผ์ด์„ผ์Šค ๋น„์šฉ ๋ฌธ์ œ๋กœ ์ผ๋‹จ ๊ณ ๋ คํ•˜์ง€ ์•Š์•˜๋‹ค.

(์‚ฝ์งˆ ๋„ˆ๋ฌด ํ•˜๋‹ค๊ฐ€ ์ง€์ณ์„œ ๊ทธ๋ƒฅ ๋ˆ๋‚ด๊ณ  ์“ธ๋ ค๊ณ  ํ•˜๋‹ค๊ฐ€ ์ด ๋ฐฉ๋ฒ•์œผ๋กœ ์„ฑ๊ณตํ•ด์„œ ์‚ฌ์šฉํ•˜์ง€ ์•Š์Œ)

 

๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์œผ๋กœ๋Š” ํ˜„์žฌ ์‚ฌ์šฉํ•œ ๋ฐฉ๋ฒ•์ฒ˜๋Ÿผ AWS์˜ EC2๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•, ๊ทธ๋ฆฌ๊ณ  ์—ฌ๋Ÿฌ ์šด์˜์ฒด์ œ์—์„œ ๋‹ค์–‘ํ•œ ๋ฐฉ๋ฒ•์ด ์žˆ์—ˆ์ง€๋งŒ ์ตœ์ข…์ ์œผ๋กœ EC2์—์„œ ํ”„๋ฆฌํ‹ฐ์–ด์— ์ œ๊ณตํ•˜๋Š” t2.micro๋Š” ๋ฉ”๋ชจ๋ฆฌ๊ฐ€ 1GB๋กœ Oracle21cXE ์„ค์น˜๊ฐ€ ๋ถˆ๊ฐ€ ํ–ˆ๋‹ค.

 

GCP(Google Cloud Platform)์—์„œ๋Š” ์‹ ๊ทœ ์‚ฌ์šฉ์ž์—๊ฒŒ ์ผ์ • ํฌ๋ ˆ๋”ง์„ ์ œ๊ณตํ•˜๊ณ  ๊ทธ ํฌ๋ ˆ๋”ง ๋งŒํผ ๋ฌด๋ฃŒ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค.

 

(์˜ค๋ผํด ๋ฆฌ๋ˆ…์Šค๋ฅผ ์ด์šฉํ•œ ์„ค์น˜๊ฐ€ ๊ฐ„ํŽธํ–ˆ์ง€๋งŒ ์˜ค๋ผํด ํด๋ผ์šฐ๋“œ ํšŒ์›๊ฐ€์ž…์— ์‹คํŒจใ…œใ…œ)

 

GCP์— ํšŒ์›๊ฐ€์ž… ํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ์ด๋ฏธ ํ”ํ•ด์„œ ํ•„์š”ํ•œ VM instance ์ƒ์„ฑ๊ณผ ์„ค์ •ํ•˜๋Š” ๋‚ด์šฉ๋งŒ ์ •๋ฆฌ ํ–ˆ๋‹ค.

 

 

์—ฌ๊ธฐ์„œ ํ•ด์•ผ ํ• ๊ฒƒ 

 

1) VM instance ์ƒ์„ฑ

2) ์ƒ์„ฑํ•œ instance์˜ ์™ธ๋ถ€ ip ์ฃผ์†Œ ์•Œ๊ธฐ

3) SSH ํ‚ค ์„ค์ • (Public key ๋“ฑ๋ก)


1) VM instance ์ƒ์„ฑ

(ํšŒ์› ๊ฐ€์ž… ํ›„ ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ, VPC ์ƒ์„ฑ ํ›„ VM instance ์ƒ์„ฑ์ด ๊ฐ€๋Šฅ ํ–ˆ๋˜ ๊ฒƒ ๊ฐ™๋‹ค.)

๋”๋ณด๊ธฐ

1. GCP ์„œ๋น„์Šค ์ค‘์— Compute Engine์˜ VM instance์— ๋“ค์–ด๊ฐ€๋ฉด

2. ์ƒ๋‹จ์˜ CREATE INSTANCE ๋ฉ”๋‰ด๋ฅผ ํ†ตํ•ด VM instance๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค.

 

3. ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ธฐ์ค€์œผ๋กœ ์„ค์ •ํ•˜๊ณ  ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑ ํ•œ๋‹ค.

  • Name : ์ธ์Šคํ„ด์Šค๋ฅผ ๊ตฌ๋ณ„ํ•  ์ˆ˜ ์žˆ๋Š” ์ด๋ฆ„
    • (์˜์†Œ๋ฌธ์ž, ์ˆซ์ž, ํ•˜์ดํ”ˆ๋งŒ ์‚ฌ์šฉ ๊ฐ€๋Šฅ | ์˜์†Œ๋ฌธ์ž๋กœ ์‹œ์ž‘ํ•ด์•ผํ•จ | ํ•˜์ดํ”ˆ์œผ๋กœ ๋๋‚˜๋ฉด ์•ˆ๋จ)
  • Region : asia-northeast3 (Seoul)
    • ๊ฐ€๊นŒ์šด ๊ณณ์œผ๋กœ ์„ค์ •
  • Zone : ์•„๋ฌด๊ฑฐ๋‚˜
    • ์„ค์ •ํ•œ ๋ฆฌ์ „ ์ค‘์— ์–ด๋””๋ฅผ ์“ธ๊ฑฐ๋ƒ๋ฅผ ์„ ํƒํ•˜๋Š” ๊ฑด๋ฐ ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ ํ›„์—๋Š” ๋ณ€๊ฒฝ์ด ๋˜์ง€ ์•Š๋Š”๋‹ค๊ณ  ํ•จ

 

  • Machine configuration : 
    • ์—ฌ๋Ÿฌ์ง€ ํƒ€์ž…์ค‘์— ํฌ๊ฒŒ ์ƒ๊ด€ ์—†๋Š” ๊ฒƒ ๊ฐ™๋‹ค. ํŠน๋ณ„ํ•˜๊ฒŒ ๊ณ ๋ คํ•ด์•ผ ํ•˜๋Š” ์‚ฌํ•ญ์ด ์žˆ๋‹ค๋ฉด ์กฐ๊ฑด์„ ์ถฉ์กฑํ•˜๋Š” ๋จธ์‹ ์œผ๋กœ ์„ ํƒ
  • Machine type : 2G ์ด์ƒ์˜ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ๊ฐ€์ง€๋Š” ๊ฑธ๋กœ ํ”„๋ฆฌ์…‹ ๋˜๋Š” ์ปค์Šคํ…€ ์ค‘์— ์„ ํƒ

 

  • Boot disk → CHANGE
    • PUBLIC IMAGES ์ค‘์— ๋‹ค์Œ์œผ๋กœ ์„ ํƒ
      • Operating system : CentOS
      • Version : CentOS 7
      • Boot disk type : SSD persistent disk
        • ์ด๊ฑด ๋‚ด๋งˆ์Œ๋Œ€๋กœ ๊ทธ๋ƒฅ ์„ ํƒ SSD๊ฐ€ ๋น ๋ฅผ๊ฑฐ ๊ฐ™์œผ๋‹ˆ๊นŒ..?ใ…Žใ…Ž
      • Size (GB) : 20
        • ์‚ฌ์šฉํ•  ๋ฐ์ดํ„ฐ ์–‘์— ๋”ฐ๋ผ์„œ ์กฐ์ •ํ•ด์„œ ์„ค์ •
      ⇒ select  ๋ˆ„๋ฅด๋ฉด ๋ถ€ํŒ… ๋””์Šคํฌ ์„ค์ • ์™„๋ฃŒ

 

์ด๋ ‡๊ฒŒ ์„ค์ • ํ•œ ๋Œ€๋กœ CREATE ๋ฅผ ๋ˆ„๋ฅด๋ฉด ์ธ์Šคํ„ด์Šค๊ฐ€ ์ƒ์„ฑ๋œ๋‹ค.

 


CREATE INSTANCE๋ฅผ ํ–ˆ๋˜ ํŽ˜์ด์ง€๋กœ ๋“ค์–ด๊ฐ€๋ฉด

์ด๋ ‡๊ฒŒ ์ƒ์„ฑํ•œ ์ธ์Šคํ„ด์Šค๋ฅผ ํ™•์ธ ํ•  ์ˆ˜ ์žˆ๋‹ค.

(์„ค์ •์— ๋”ฐ๋ผ ๋‹ค๋ฅด๊ฒ ์ง€๋งŒ ๋‚˜๋Š” ๊ธˆ๋ฐฉ ์ƒ๊ฒผ๊ณ  1๋ถ„ ์ด๋‚ด๋กœ ์ •์ƒ์ ์œผ๋กœ ๊ตฌ๋™ ๋˜๋Š” ๊ฒƒ์ด ๋ณด์˜€๋‹ค.)

 

2) ์ƒ์„ฑํ•œ VM instance์˜ ์™ธ๋ถ€ ip ์ฃผ์†Œ ์•Œ๊ธฐ

๋”๋ณด๊ธฐ

์ธ์Šคํ„ด์Šค ๋ชฉ๋ก์—์„œ ๋ณด์ด๋Š” External IP๊ฐ€ ์ธ์Šคํ„ด์Šค์˜ pubilc ip ์ด๋‹ค.

โ€ป ์œ ๋™ip ์ด๊ณ , ์ธ์Šคํ„ด์Šค๋ฅผ ๊ป๋‹ค ์ผœ๋ฉด ๋ณ€๊ฒฝ๋œ๋‹ค๋Š” ์  ์ฃผ์˜

    ๊ณ ์ •ip๋กœ ์‚ฌ์šฉํ•˜๋Š”๊ฒƒ์€ ๋น„์šฉ ์†Œ์š”๋˜๋Š” ๊ฒƒ์œผ๋กœ ์•ˆ๋‹ค.(aws, naver cloud๋Š” ํ™•์‹คํ•˜๊ฒŒ ๋น„์šฉ ์†Œ์š”๋จ)

 

3) SSH ํ‚ค ์„ค์ •

๋”๋ณด๊ธฐ

์•ž์„  ๊ธ€์—์„œ ์ค€๋น„ํ•œ public key๋ฅผ ๋“ฑ๋กํ•ด์ค˜์•ผ ํ•œ๋‹ค.

 

1. ์‚ฌ์ด๋“œ ๋ฉ”๋‰ด์ค‘ ๋ฐ‘์œผ๋กœ ๋‚ด๋ ค๊ฐ€๋ฉด Metadata๋ผ๋Š” ๋ฉ”๋‰ด๊ฐ€ ์žˆ๋‹ค. ์—ฌ๊ธฐ๋กœ ๋“ค์–ด๊ฐ„๋‹ค.

2. Metadata ๋ฉ”๋‰ด ๋‚ด์˜ ์ƒ๋‹จ ํƒญ์—์„œ SSH KEYS์— ๋“ค์–ด๊ฐ„ ๋’ค ADD SSH KEY๋ฅผ ๋ˆ„๋ฅธ๋‹ค.

3.์•ž์„œ PuTTYgen์œผ๋กœ ์ƒ์„ฑ ํ›„ ๋”ฐ๋กœ ๋ณต์‚ฌํ•ด ๋‘์—ˆ๋˜ public key๋ฅผ ์ž…๋ ฅํ›„ ์ €์žฅํ•œ๋‹ค.


์ด๋ ‡๊ฒŒ ํ•œ ํ›„ SSH๋กœ VM ์ธ์Šคํ„ด์Šค์— ์ ‘์†ํ•˜๊ณ  ์„ค์น˜ํ•˜๋Š” ๊ณผ์ •์„ ์ง„ํ–‰ ํ•  ์ˆ˜ ์žˆ๋‹ค.

๋ฐ˜์‘ํ˜•

Oracle์„ ์ด์šฉํ–ˆ๋˜ ํŒ€ ํ”„๋กœ์ ํŠธ๋ฅผ ํด๋ผ์šฐ๋“œ ํ™˜๊ฒฝ์— ๋ฐฐํฌํ•ด ๋ณด๊ธฐ ์œ„ํ•ด

ํด๋ผ์šฐ๋“œ ํ™˜๊ฒฝ์— OracleDatabase ์„ค์น˜๋ฅผ ์‹œ๋„ํ–ˆ๋‹ค.

์—ฌ๋Ÿฌ๊ฐ€์ง€ ๋ฐฉ๋ฒ•์„ ์‹œ๋„ ํ–ˆ์ง€๋งŒ ์ „๋ฐ˜์ ์œผ๋กœ ๋ถ€์กฑํ•œ ์ง€์‹ ๋“ฑ๋“ฑ์˜ ๋ฌธ์ œ๋กœ

2~3์ผ์€ ์‚ฝ์งˆ ํ•œ ๋์— ์„ค์น˜์™€ ์—ฐ๋™์— ์„ฑ๊ณตํ–ˆ๋‹ค.

 

๋ณด์•ˆ์  ์ด์Šˆ, ๊ทธ์™ธ ์—ฌ๋Ÿฌ๊ฐ€์ง€ ๋ฌธ์ œ์ ๋“ค์ด ์žˆ๋Š” ๋ฐฉ๋ฒ•์ด์ง€๋งŒ

์„ฑ๊ณตํ•ด ๋ณธ ๊ฒƒ ๋งŒ์œผ๋กœ๋„ ์•„์ฃผ ๋ฒ…์ฐจ๊ณ  ์‹ ๋‚˜๊ธฐ ๋•Œ๋ฌธ์— ๊ธฐ๋กํ•ด ๋‘๊ณ 

๋‚˜์ค‘์— ๋ถ€๋ถ„๋ถ€๋ถ„ ๊ฐœ์„  ํ•˜๋ ค๊ณ  ํ•œ๋‹ค.

 

์ง€์‹์ด ์•„์ฃผ ์งง์€ ๋‚ด ๊ธฐ์ค€์˜ ๋ฐฉ๋ฒ• (2023. 8. ๊ธฐ์ค€)


ํด๋ผ์šฐ๋“œ ํ™˜๊ฒฝ์— Oracle 21c XE๋ฅผ ์„ค์น˜ํ•˜๊ณ  ์—ฐ๋™ํ•˜๋Š” ๊ฒƒ์€ ํฌ๊ฒŒ 3๋‹จ๊ณ„๋กœ ๋‚˜๋ˆ„์–ด ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

 

  1. GCP(Google Cloud Platform)์— VM instance ์ƒ์„ฑ 
  2. Oracle21c XE ์„ค์น˜
  3. DB ์ ‘์† ๋ฐ ํ”„๋กœ์ ํŠธ ์—ฐ๋™

 

๊ทธ๋ฆฌ๊ณ  ์ด๊ณผ์ •๋“ค์„ ์ˆœ์กฐ๋กญ๊ฒŒ ์ง„ํ–‰ํ•˜๊ธฐ ์œ„ํ•ด ๋ฏธ๋ฆฌ ์ค€๋น„ ํ•ด์•ผ ํ•  ๊ฒƒ๋“ค์ด ์žˆ๋‹ค.

  • SSH ํ‚ค
  • Oracle 21cXE ์„ค์น˜ ํŒŒ์ผ(.rpm)
  • FileZilla : Oracle 21c XE ์„ค์น˜ ํŒŒ์ผ์„ VM instance์— ์ „์†กํ•˜๊ธฐ ์œ„ํ•œ ์šฉ๋„

 

์ด ๊ธ€์€ ์‚ฌ์ „ ์ค€๋น„ ์‚ฌํ•ญ๋“ค์— ๋Œ€ํ•œ ๋‚ด์šฉ์ด๋‹ค.

 

 

1) SSH ํ‚ค - PuTTYgen ์ด์šฉ

๋”๋ณด๊ธฐ

https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html

 

Download PuTTY: latest release (0.78)

This page contains download links for the latest released version of PuTTY. Currently this is 0.78, released on 2022-10-29. When new releases come out, this page will update to contain the latest, so this is a good page to bookmark or link to. Alternativel

www.chiark.greenend.org.uk

1. ์œ„์˜ ํ™ˆํŽ˜์ด์ง€ ์—์„œ ํŒจํ‚ค์ง€(๋‹ค์šด๋กœ๋“œ ํ›„ ์„ค์น˜)

๋˜๋Š” PuTTYgen ๋‹จ์ผ ํŒŒ์ผ์„ ๋‹ค์šด๋กœ๋“œ ๋ฐ›์€ ๋’ค PuTTYgen.exe ํŒŒ์ผ ์‹คํ–‰

2.Generate๋ฅผ ๋ˆŒ๋Ÿฌ์„œ ํ‚ค ์ƒ์„ฑ (์ฒ˜์Œ์—” ๋น ๋ฅธ๊ฒƒ ๊ฐ™์ง€๋งŒ ๊ฝค ์˜ค๋žœ ์‹œ๊ฐ„์ด ๊ฑธ๋ฆผ)

 

3. ํ‚ค๊ฐ€ ์ƒ์„ฑ๋˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ํ™”๋ฉด์ด ๋‚˜์˜ค๊ณ  ์—ฌ๊ธฐ์„œ 3๊ฐ€์ง€๊ฐ€ ํ•„์š”ํ•˜๋‹ค.

    - Public key, Key Comment, Private key file


โ‘  Public key : ํ•ด๋‹น ๋ถ€๋ถ„์„ ๋‚ด์šฉ์„ ๋ชจ๋‘ ๋ณต์‚ฌํ•ด์„œ ๋ฉ”๋ชจ์žฅ์— ๋”ฐ๋กœ ์ €์žฅ ํ•ด ๋‘”๋‹ค.

โ‘ก Key comment : ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ๋”ฐ๋กœ ์ ์–ด๋‘๊ฑฐ๋‚˜ ์•Œ๊ณ  ์žˆ๋Š”๋‹ค.( ๋˜๋Š” Public key ๋งˆ์ง€๋ง‰ ๋ถ€๋ถ„์— ์žˆ์Œ)

โ‘ข Private key file : Save private key๋ฅผ ๋ˆŒ๋Ÿฌ ๋‚˜์ค‘์— ์ฐพ์„ ์ˆ˜ ์žˆ๋Š” ๊ฒฝ๋กœ์— ์•Œ์•„ ๋ณผ ์ˆ˜ ์žˆ๋Š” ์ด๋ฆ„์œผ๋กœ ์ €์žฅํ•ด ๋‘”๋‹ค.

    (ex. gcp-private-key )

 

2) Oracle 21cXE ์„ค์น˜ ํŒŒ์ผ(.rpm)

๋”๋ณด๊ธฐ

https://www.oracle.com/database/technologies/xe-downloads.html

 

Oracle Database Express Edition (XE) Downloads

Support Oracle Database Express Edition (XE) is a community supported edition of the Oracle Database family. Please go to the Oracle Database XE Community Support Forum for help, feedback, and enhancement requests. Note: Oracle Support Services only provid

www.oracle.com

์˜ค๋ผํด ํ™ˆํŽ˜์ด์ง€์—์„œ .rpmํ˜•์‹์˜ ์„ค์น˜ ํŒŒ์ผ์„ ๋‹ค์šด๋กœ๋“œํ•œ๋‹ค.

๋‚˜๋Š” centOS7์„ ์‚ฌ์šฉํ•  ๊ฒƒ์ด๋ผ์„œ Oracle Database 21c Express Edition for Linux x64 ( OL7 ) ๋ฅผ ๋‹ค์šด๋ฐ›์Œ

์šฉ๋Ÿ‰์ด ํฌ๊ธฐ ๋•Œ๋ฌธ์— ์ด๊ฒƒ๋„ ์‹œ๊ฐ„์ด ์ข€ ๊ฑธ๋ฆผ.

 

3) FileZilla ํ”„๋กœ๊ทธ๋žจ

๋”๋ณด๊ธฐ

์œ„์—์„œ ์ค€๋น„ํ•œ Oracle21cXE ์„ค์น˜ ํŒŒ์ผ์„ ํด๋ผ์šฐ๋“œํ™˜๊ฒฝ์œผ๋กœ ์ „์†กํ•˜๊ธฐ ์œ„ํ•œ ํ”„๋กœ๊ทธ๋žจ. ๋‹ค๋ฅธ ๊ฒƒ๋“ค๋„ ๋งŽ์ง€๋งŒ FileZilla๋ฅผ ๋ณดํ†ต ๋งŽ์ด ์“ฐ๋Š”๊ฒƒ ๊ฐ™๋‹ค.

https://filezilla-project.org/

์œ„์˜ ํ™ˆํŽ˜์ด์ง€์—์„œ Cilent๋ฅผ ๋‹ค์šด ๋ฐ›์•„์„œ ์„ค์น˜ํ•œ๋‹ค.

์„ค์น˜์—๋Š” ๋ณ„๋‹ค๋ฅธ ์„ค์ • ํ•„์š” ์—†์ด ๊ทธ๋ƒฅ ๋‹ค์Œ ๊ณ„์† ๋ˆŒ๋Ÿฌ์„œ ์„ค์น˜.

์ด๋ ‡๊ฒŒ ์ค€๋น„๋ฅผ ํ•ด๋†“๊ณ  ์ด์ œ ๋ณธ๊ฒฉ์ ์œผ๋กœ ์‹œ์ž‘ํ•œ๋‹ค.

๋ฐ˜์‘ํ˜•

ํ”„๋กœ์ ํŠธ๋ฅผ ํด๋ผ์šฐ๋“œ ํ™˜๊ฒฝ์— ๋ฐฐํฌํ•˜๋Š” ๊ณผ์ • ์ค‘์— ๋ชจ๋ฅด๋Š”๊ฒƒ, ๋ฌธ์ œ๋“ค์— ๋Œ€ํ•ด์„œ ๋‹ค์‹œ ์ฐพ์•„๋ณด๋Š” ์‹œ๊ฐ„์„ ์ค„์ด๊ธฐ ์œ„ํ•ด ์ž‘์„ฑ

Spring Framework๋กœ ์ž‘์„ฑํ–ˆ๋˜ ๊ฐœ์ธ ํ”„๋กœ์ ํŠธ์˜ pom.xml ์ตœ์ƒ๋‹จ ๋ถ€๋ถ„. ์•„๋ž˜๋กœ๋Š” ์˜์กด์„ฑ ์ฃผ์ž…์„ ํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ? ๋“ค์— ๋Œ€ํ•œ ๋‚ด์šฉ์ด ์žˆ์Œ.

groupId,  artiactedId, version ๊ฐ ํ”„๋กœ์ ํŠธ๋ณ„๋กœ ์žˆ๊ณ  ์˜์กด์„ฑ์ฃผ์ž…์„ ํ•œ ํ”„๋กœ์ ํŠธ๋“ค์—๋„ ๋ชจ๋‘ ์žˆ๋‹ค๋Š” ๊ฒƒ์„ ์•Œ ์ˆ˜ ์žˆ๋‹ค.

์ตœ์ƒ๋‹จ์˜ ๋‚ด์šฉ์€ ๋‚ด๊ฐ€ ์ž‘์„ฑํ•œ ํ”„๋กœ์ ํŠธ์— ๋Œ€ํ•œ groupId,  artiactedId, version์„ ์˜๋ฏธํ•œ๋‹ค.

 

[๊ณต์‹ ๋ฌธ์„œ์˜ ์„ค๋ช… + ์ฐพ์•„๋ณธ ์ •๋ณด]

groupId: ๋ชจ๋“  ํ”„๋กœ์ ํŠธ์—์„œ ๊ฐ ํ”„๋กœ์ ํŠธ๋ฅผ ๊ณ ์œ ํ•˜๊ฒŒ ์‹๋ณ„ํ•˜๋Š” ๊ฒƒ

- Java์˜ ํŒจํ‚ค์ง€ ์ด๋ฆ„ ๊ทœ์น™์„ ๋”ฐ๋ผ์•ผ ํ•œ๋‹ค.

(๊ฐ•์ œ ๊ทœ์น™์€ ์•„๋‹ˆ์ง€๋งŒ ์—ญ๋„๋ฉ”์ธ์ด๋ฆ„(์ฆ‰, Java ํŒจํ‚ค์ง€ ์ด๋ฆ„)์„ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ  ๋‹จ์–ดํ•˜๋‚˜๋กœ ์“ฐ๋ฉด

  Maven Central ์ €์žฅ์†Œ์—์„œ ํ”„๋กœ์ ํŠธ์˜ ID๋กœ ์Šน์ธ ๋ฐ›๊ธฐ ์–ด๋ ค์šธ ๊ฒƒ)

- Java ํŒจํ‚ค์ง€ ์ด๋ฆ„ ๊ทœ์น™์„ ๋”ฐ๋ผ์„œ ํ•˜์œ„๊ทธ๋ฃน์„ ์ƒ์„ฑํ•  ์ˆ˜ ๋„ ์žˆ์Œ

artifactId: ๋ฒ„์ „ ์—†์ด jar ํŒŒ์ผ์˜ ์ด๋ฆ„

- ์†Œ๋ฌธ์ž๋กœ ๋œ ๋ฌธ์ž๋งŒ ์‚ฌ์šฉํ•ด์•ผ ํ•จ

- ๋‹ค๋ฅธ ์‚ฌ๋žŒ์ด ๋งŒ๋“  jar ํŒŒ์ผ์ธ ๊ฒฝ์šฐ ๋ฐฐํฌ๋˜๋Š” ์ด๋ฆ„์„ ๊ทธ๋Œ€๋กœ ์‚ฌ์šฉํ•ด์•ผ ํ•จ
์˜ˆ: maven, commons-math

- ์›น ํ”„๋กœ์ ํŠธ์˜ Context root๋กœ ์ž๋™ ์„ค์ •๋œ๋‹ค. → ์ด Context root๋Š” ๋ฐฐํฌํ• ๋•Œ url ์„ค์ •๊ณผ ๊ด€๋ จ ์žˆ..๋Š”๊ฑฐ ๊ฐ™์Œ

pom.xml์—  artifactId๊ฐ€ controller๋กœ ๋˜์–ด์žˆ์–ด์„œ Context root๋„ /controller ๋กœ ๋˜์–ด ์žˆ์Œ.

์™œ ์ €๋ ‡๊ฒŒ ํ•ด๋†จ๋Š”์ง€๋Š” ๋‹น์—ฐํžˆ ๋ชจ๋ฆ„... ๊ทธ๋ƒฅ ํ”„๋กœ์ ํŠธ์— ๋Œ€ํ•œ setting์„ ๋ณต์‚ฌํ•ด์„œ ์จ์„œ ๊ทธ๋Ÿฐ๊ฒƒ ๊ฐ™์Œ. ๊ทธ๋ž˜์„œ artifactId์™€ ํ•จ๊ป˜ ๋ฐ”๊ฟˆ

 

 

 

 

 

 

 

 

 

version: ๋ง๊ทธ๋Œ€๋กœ ๋ฐฐํฌํ•˜๋Š” ํ”„๋กœ์ ํŠธ์˜ ๋ฒ„์ „

- ์ผ๋ฐ˜์ ์ธ ํ˜•ํƒœ (1.0, 1.1, 1.0.1 ๋“ฑ)๋ฅผ ์‚ฌ์šฉํ• ์ˆ˜ ์žˆ์ง€๋งŒ,

๋‚ ์งœ๋Š” ๋ณดํ†ต SNAPSHOT ๋นŒ๋“œ์™€ ์—ฐ๊ด€๋˜๊ธฐ ๋•Œ๋ฌธ์— ์‚ฌ์šฉํ•˜์ง€ ์•Š๋„๋ก ํ•จ.

- ๋‹ค๋ฅธ์‚ฌ๋žŒ์˜ artifact์ธ ๊ฒฝ์šฐ ๋ฒ„์ „ ๋ฒˆํ˜ธ ์›๋ž˜ ์ ํžŒ ๊ทธ๋Œ€๋กœ ์‚ฌ์šฉํ•ด์•ผ ํ•จ.

 

์ถœ์ฒ˜ : https://maven.apache.org/guides/mini/guide-naming-conventions.html

 

Maven – Guide to Naming Conventions

 

maven.apache.org

Guide to naming conventions on groupId, artifactId, and version

  • groupId uniquely identifies your project across all projects. A group ID should follow Java's package name rules. This means it starts with a reversed domain name you control. For example,org.apache.maven, org.apache.commonsYou can create as many subgroups as you want. A good way to determine the granularity of the groupId is to use the project structure. That is, if the current project is a multiple module project, it should append a new identifier to the parent's groupId. For example,
  • org.apache.maven, org.apache.maven.plugins, org.apache.maven.reporting
  • Maven does not enforce this rule. There are many legacy projects that do not follow this convention and instead use single word group IDs. However, it will be difficult to get a new single word group ID approved for inclusion in the Maven Central repository.
  • artifactId is the name of the jar without version. If you created it, then you can choose whatever name you want with lowercase letters and no strange symbols. If it's a third party jar, you have to take the name of the jar as it's distributed.eg. maven, commons-math
  • version if you distribute it, then you can choose any typical version with numbers and dots (1.0, 1.1, 1.0.1, ...). Don't use dates as they are usually associated with SNAPSHOT (nightly) builds. If it's a third party artifact, you have to use their version number whatever it is, and as strange as it can look. For example,2.0, 2.0.1, 1.3.1

+ ์œ„์˜ ์ •๋ณด๋“ค์„ ํ†ตํ•ด์„œ ์•„๋ž˜์™€ ๊ฐ™์ด ์—ฌ๋Ÿฌ ํ”„๋กœ์ ํŠธ๋“ค์ด ํŠธ๋ฆฌ ํ˜•ํƒœ๋ฅผ ๋งŒ๋“ ๋‹ค๊ณ  ํ•จ.

    ⇒๋‹ค๋ฅธ ํ”„๋กœ์ ํŠธ์—์„œ ๋‚˜์˜ ํ”„๋กœ์ ํŠธ๋ฅผ ์‚ฌ์šฉํ• ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ์‹๋ณ„์ž๋ผ๊ณ  ์ƒ๊ฐํ•˜๋ฉด๋  ๊ฒƒ ๊ฐ™์Œ

packaging : ํŒจํ‚ค์ง• ํ•  ํ˜•์‹

๋นŒ๋“œ ํ›„ ํ”„๋กœ์ ํŠธ ํŒŒ์ผ์˜ ์ด๋ฆ„๊ณผ ํ˜•์‹์ด ์ด๋ ‡๊ฒŒ ์ƒ์„ฑ๋œ๋‹ค.

 

์ถœ์ฒ˜ : https://youtu.be/KNGQ9JBQWhQ

 

๋ฐ˜์‘ํ˜•
๋ฐฐ์—ด Array

๋ฐฐ์—ด Array

๊ฐ™์€ ํƒ€์ž…์˜ ์—ฌ๋Ÿฌ ๋ณ€์ˆ˜๋ฅผ ์—ฐ์†๋œ ํ•˜๋‚˜์˜ ๋ฌถ์Œ์œผ๋กœ ๋‹ค๋ฃจ๋Š” ๊ฒƒ

โ€ป ๋ฐฐ์—ด๋ณด๋‹ค๋Š” Collectoral Class๋ฅผ ๋” ๋งŽ์ด ์‚ฌ์šฉํ•จ (๊ฐ€๋ณ€์„ฑ์ด ์žˆ์Œ)

List, Array List, โ€ฆ

๐Ÿ“Œ
indexใ€€โ†’ใ€€๋ฐฐ์—ด์˜ ์ˆœ์„œ๋ฅผ ๊ฐ€๋ฅดํ‚ค๋Š” ์ˆซ์ž ๋ณ€์ˆ˜ํ…Œ์ด๋ธ”ใ€€โ†’ใ€€์‹คํ–‰ํŒŒ์ผ ์•ˆ์— ๋“ค์–ด๊ฐ
๋ฐฐ์—ด์˜ ์ธ์ˆ˜ ์ถœ๋ ฅ ๋ฐฉ์‹
  • ๊ธฐ๋ณธ๋ฐฉ์‹
for(int i = 0; i < a.length; i++)
System.out.print(a[i]);

  • ๋ฐฐ์—ด ์ „์šฉ (๋” ๋งŽ์ด ์‚ฌ์šฉํ•จ)
for(int b:a)
System.out.print(b + " ");
//intํ˜•์„ ๊ฐ€์ง„ ๋ฐฐ์—ด์˜ ์š”์†Œ๋ฅผ ๊ฐœ์ˆ˜๋งŒํผ ์ถœ๋ ฅ
๋ฐฐ์—ด์˜ ์„ ์–ธ, ์ƒ์„ฑ, ์ดˆ๊ธฐํ™”/์ •์˜
์„ ์–ธ โ†’ ์ฐธ์กฐํ˜• ๋ณ€์ˆ˜ ์„ ์–ธ
์ƒ์„ฑ๋œ ๋ฐฐ์—ด์„ ๋‹ค๋ฃจ๊ธฐ ์œ„ํ•œ ์ฐธ์กฐ ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธ
ํƒ€์ž…[] ๋ณ€์ˆ˜์ด๋ฆ„;
int[] score;
String[] name;
ํƒ€์ž… ๋ณ€์ˆ˜์ด๋ฆ„[];
int score[];
String name[];

์ƒ์„ฑ โ†’ ๋ฉ”๋ชจ๋ฆฌ ๊ณต๊ฐ„ ํ• ๋‹น
๊ฐ’์„ ์ €์žฅํ•  ์ˆ˜ ์žˆ๋Š” ๊ณต๊ฐ„์ด ๋งŒ๋“ค์–ด์ง€๋Š” ๊ฒƒ
๐Ÿ“Œ
newใ€€โ†’ใ€€๋ฉ”๋ชจ๋ฆฌ๋ฅผ ํ• ๋‹น ์‹œ์ผœ์„œ ๊ฐ์ฒด๋ฅผ ํ˜•์„ฑํ•ด์„œ ๊ทธ ๊ฐ์ฒด๊ฐ€ ์œ„์น˜ํ•œ ๋ฉ”๋ชจ๋ฆฌ์˜ ์ฃผ์†Œ๋ฅผ ํ• ๋‹น
์„ ์–ธ๊ณผ ์ƒ์„ฑ์„ ๋”ฐ๋กœ
  • ๋ณ€์ˆ˜์ด๋ฆ„ = new ํƒ€์ž…[๊ธธ์ด];
    int[] score;  //์„ ์–ธ
    score = new int[5];  //์ƒ์„ฑ
    String[] name;
    name = new String[10];
์„ ์–ธ๊ณผ ์ƒ์„ฑ์„ ํ•œ๋ฒˆ์— ํ•  ๋•Œ
  • ํƒ€์ž…[] ๋ณ€์ˆ˜์ด๋ฆ„ = new ํƒ€์ž…[๊ธธ์ด];
    int[] score = new int[5];
    String[] name = new String[10];
  • ์ƒ์„ฑ๊ณผ ๋™์‹œ์— ๊ฐ ๋ณ€์ˆ˜ ํƒ€์ž…์˜ ๊ธฐ๋ณธ๊ฐ’์ด ์›์†Œ์˜ ๊ฐ’์ด ๋œ๋‹ค.
์ดˆ๊ธฐํ™”/์ •์˜ โ†’ ๊ฐ’ ์ž…๋ ฅ
int[] ๋ณ€์ˆ˜๋ช… = {1, 2, 3, 4, 5}  /* 20๋ฐ”์ดํŠธ์˜ ๋ฉ”๋ชจ๋ฆฌ ๊ณต๊ฐ„์ด ํ™•๋ณด๋˜๊ณ  ๊ฐ 4๋ฐ”์ดํŠธ๋งˆ๋‹ค intํ˜• ๊ฐ’์ด ์ €์žฅ
																  a ๋ผ๋Š” ๋ฐฐ์—ด์€ 5๊ฐœ์˜ element(์š”์†Œ, ์›์†Œ)๋ฅผ ๊ฐ€์ง„ ๊ฒƒ์œผ๋กœ ํ™•์ •
																  = ๋ฐฐ์—ด์˜ ๊ธธ์ด๋ฅผ ํ™•์ • = ๋ฐฐ์—ด์˜ size๊ฐ€ ๋น„๊ฐ€๋ณ€์ด๋‹ค */
int [] ๋ณ€์ˆ˜๋ช… = new int[]{1, 2, 3, 4, 5}; 
//๋ฉ”๋ชจ๋ฆฌ ํ• ๋‹น๊ณผ ๊ฐ’๊นŒ์ง€ ์ •์˜
๋ฐฐ์—ด์˜ ์ธ๋ฑ์Šค
๋ฐฐ์—ด์˜ ๊ธธ์ด
  • ๋ฐฐ์—ด์€ ํ•œ๋ฒˆ ์ƒ์„ฑ ํ•˜๋ฉด ๊ธธ์ด๋ฅผ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์—†์Œ
  • JVM์ด ๋ชจ๋“  ๋ฐฐ์—ด์˜ ๊ธธ์ด๋ฅผ ๋ณ„๋„๋กœ ๊ด€๋ฆฌํ•˜๋ฉฐ ๋‹ค์Œ์œผ๋กœ ๊ธธ์ด์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ์Œ
    ๋ฐฐ์—ด์ด๋ฆ„.length

    • ex) ๋ฐฐ์—ด์˜ ๊ธธ์ด๊ฐ€ ๋ณ€๊ฒฝ๋˜๋ฉด ๋ฐ˜๋ณต๋ฌธ ๋“ฑ์— ์ž๋™์œผ๋กœ ์ ์šฉ๋˜๋„๋ก ๋งŽ์ด ์‚ฌ์šฉ ํ•จ
      int[] score = new int[6];
      for(int i = 0; i < score.length; i++)
      	Systme.out.println(score[i]);
์ถœ๋ ฅ
for๋ฌธ ์ด์šฉ
int[] iArr = { 100, 95, 80, 70, 60 };
for(int i = 0; i < iArr.length; i++) {
	System.out.println(iArr[i] +",");
}

โ‡’100,50,60,80,90,

Arrays.toString(๋ฐฐ์—ด์ด๋ฆ„) ์ด์šฉ
  • ๋ฐฐ์—ด ๋‚ด์šฉ์„ ๋ฐ”๋กœ ์ถœ๋ ฅํ•˜๋Š” ๊ฒฝ์šฐ โ€˜ํƒ€์ž…โ€™@โ€™์ฃผ์†Œโ€™์˜ ํ˜•์‹์œผ๋กœ ์ถœ๋ ฅ
    int[] iArr = { 100, 95, 80, 70, 60 };
    System.out.print(iArr);

    โ‡’[I@515f550a

  • Arrays.toString() ์‚ฌ์šฉ ์œ„ํ•ด์„œ๋Š” import java.util.Arrays; ํ•„์š”
    import java.util.Arrays;
    
    int[] iArr = { 100, 95, 80, 70, 60 };
    System.out.print(Arrays.toString(iArr));

    โ‡’ [100, 50, 60, 80, 90]

2์ฐจ์› ๋ฐฐ์—ด
๋ฐฐ์—ด์˜ ์„ ์–ธ, ์ƒ์„ฑ, ์ดˆ๊ธฐํ™”/์ •์˜
์„ ์–ธ โ†’ ์ฐธ์กฐํ˜• ๋ณ€์ˆ˜ ์„ ์–ธ
์ƒ์„ฑ๋  ๋ฐฐ์—ด์„ ๋‹ค๋ฃจ๊ธฐ ์œ„ํ•œ ์ฐธ์กฐ ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธ
ํƒ€์ž…[][] ๋ณ€์ˆ˜์ด๋ฆ„;
int[][] score;
String[][] name;
ํƒ€์ž… ๋ณ€์ˆ˜์ด๋ฆ„[][];
int score[][];
String name[][];

ํƒ€์ž…[] ๋ณ€์ˆ˜์ด๋ฆ„[];
int[] score[];
String[] name[];
์ƒ์„ฑ โ†’ ๋ฉ”๋ชจ๋ฆฌ ๊ณต๊ฐ„ ํ• ๋‹น
๊ฐ’์„ ์ €์žฅํ•  ์ˆ˜ ์žˆ๋Š” ๊ณต๊ฐ„์ด ๋งŒ๋“ค์–ด์ง€๋Š” ๊ฒƒ
๐Ÿ“Œ
newใ€€โ†’ใ€€๋ฉ”๋ชจ๋ฆฌ๋ฅผ ํ• ๋‹น ์‹œ์ผœ์„œ ๊ฐ์ฒด๋ฅผ ํ˜•์„ฑํ•ด์„œ ๊ทธ ๊ฐ์ฒด๊ฐ€ ์œ„์น˜ํ•œ ๋ฉ”๋ชจ๋ฆฌ์˜ ์ฃผ์†Œ๋ฅผ ํ• ๋‹น
์„ ์–ธ๊ณผ ์ƒ์„ฑ์„ ๋”ฐ๋กœ
  • ๋ณ€์ˆ˜์ด๋ฆ„ = new ํƒ€์ž…[๊ธธ์ด];
    int[][] score;  //์„ ์–ธ
    score = new int[3][4];  //์ƒ์„ฑ
์„ ์–ธ๊ณผ ์ƒ์„ฑ์„ ํ•œ๋ฒˆ์— ํ•  ๋•Œ
  • ํƒ€์ž…[][] ๋ณ€์ˆ˜์ด๋ฆ„ = new ํƒ€์ž…[ํ–‰_๊ฐœ์ˆ˜][์—ด_๊ฐœ์ˆ˜];
    int[][] score = new int[3][4];
  • ์ƒ์„ฑ๊ณผ ๋™์‹œ์— ๊ฐ ๋ณ€์ˆ˜ ํƒ€์ž…์˜ ๊ธฐ๋ณธ๊ฐ’์ด ์›์†Œ์˜ ๊ฐ’์ด ๋œ๋‹ค.
์ดˆ๊ธฐํ™”/์ •์˜ โ†’ ๊ฐ’ ์ž…๋ ฅ
int[][] arr = new int[][]{{1, 2, 3}, {4, 5, 6}};
  • ํ–‰์„ ๊ตฌ๋ถ„ํ•ด์„œ ์“ธ ์ˆ˜๋„ ์žˆ์Œ
    int[][] arr = {
    									{1, 2, 3},
    									{4, 5, 6}
    								};
int[][] arr = {{1, 2, 3}, {4, 5, 6}}; //new int[][]์ƒ๋žต

๋ฐ˜์‘ํ˜•

1. ๋ณ€์ˆ˜ ํƒ€์ž… ๊ฐ„์˜ ๋ณ€ํ™˜

1) ์ˆซ์ž ↔ ๋ฌธ์ž : ‘0’์˜ ์—ฐ์‚ฐ

  1. ์ˆซ์ž ํ˜• + ‘0’ = ๋ฌธ์ž ํ˜•ex) 3 + ‘0’ = ‘3’
  1. ๋ฌธ์ž ํ˜• - ‘0’ = ์ˆซ์ž ํ˜•ex) ‘3’ - ‘0’ = 3

2) ์ˆซ์ž ๋˜๋Š” ๋ฌธ์ž → ๋ฌธ์ž์—ด : ๋นˆ ๋ฌธ์ž์—ด ๋”ํ•˜๊ธฐ

  1. ์ˆซ์ž ํ˜• + “” = ๋ฌธ์ž์—ดex) 3 + “” = “3”
  1. ๋ฌธ์ž ํ˜• + “” = ๋ฌธ์ž์—ดex) ‘3’ + “” = “3”

3) ๋ฌธ์ž์—ด → ์ˆซ์ž : parse ๋ฉ”์„œ๋“œ ์ด์šฉ

  1. ์ˆซ์ž ํ˜•์˜ ๋ž˜ํผํด๋ž˜์Šค.parse์ˆซ์žํ˜•(๋ฌธ์ž์—ด) ⇒ ์ˆซ์ž ํ˜•ex) Interger.parseInt(”3”) = 3

 

2. ํ˜• ๋ณ€ํ™˜ ์—ฐ์‚ฐ์ž ์ด์šฉ : (๋ณ€ํ™˜ํ• ํƒ€์ž…)ํ”ผ์—ฐ์‚ฐ์ž

  1. int ↔ char : ์œ ๋‹ˆ์ฝ”๋“œ ๋ฌธ์žํ‘œ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๋ณ€ํ™˜ ๋œ๋‹ค.
  1. ์ •์ˆ˜ํ˜• ↔ ์‹ค์ˆ˜ํ˜•
    • ์ •์ˆ˜ํ˜• → ์‹ค์ˆ˜ํ˜• : ์†Œ์ˆ˜์  ์ดํ•˜ 0
    • ์‹ค์ˆ˜ํ˜• → ์ •์ˆ˜ํ˜• : ์†Œ์ˆ˜์  ์ดํ•˜ ๋ฒ„๋ฆผ

2-1. ์ž๋™ ํ˜•๋ณ€ํ™˜ : ๊ฐ’ ์†์‹ค์˜ ๊ฐ€๋Šฅ์„ฑ์ด ์—†์„ ๋•Œ ํ˜• ๋ณ€ํ™˜ ์—ฐ์‚ฐ์ž๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋”๋ผ๋„ ์ปดํŒŒ์ผ๋Ÿฌ๊ฐ€ ํ˜•๋ณ€ํ™˜์„ ์ž๋™์œผ๋กœ ์ˆ˜ํ–‰ํ•ด ์ฃผ๋Š” ๊ฒƒ

โš ๏ธ๊ฐ’ ์†์‹ค์˜ ๊ฐ€๋Šฅ์„ฑ์ด ์žˆ์„ ๋•Œ๋Š” ํ˜• ๋ณ€ํ™˜ ์—ฐ์‚ฐ์ž๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š์œผ๋ฉด ์˜ค๋ฅ˜ ๋ฐœ์ƒ!

โš ๏ธchar์™€ short์€ ๋ฉ”๋ชจ๋ฆฌ์˜ ํฌ๊ธฐ๋Š” ๊ฐ™์œผ๋‚˜ ํ‘œํ˜„ ๋ฒ”์œ„๊ฐ€ ์„œ๋กœ ๋‹ค๋ฅด๊ธฐ ๋•Œ๋ฌธ์— ์ž๋™ ํ˜• ๋ณ€ํ™˜์ด ์ผ์–ด๋‚˜์ง€ ์•Š์Œ

 

 

3. ์‚ฐ์ˆ  ๋ณ€ํ™˜ : ์ปดํŒŒ์ผ๋Ÿฌ๊ฐ€ ์—ฐ์‚ฐ ์ „์— ํ”ผ ์—ฐ์‚ฐ์ž์˜ ํƒ€์ž…์„ ์ผ์น˜ ์‹œํ‚ค๋Š” ๊ฒƒ

<๋ณ€ํ™˜ ๊ทœ์น™>

  1. ํ”ผ ์—ฐ์‚ฐ์ž๋“ค์˜ ํƒ€์ž…์ด ๋‹ค๋ฅธ ๊ฒฝ์šฐ, ๊ฐ’ ์†์‹ค์ด ์ผ์–ด๋‚˜์ง€ ์•Š๋Š” ๋ฐฉํ–ฅ์œผ๋กœ ํƒ€์ž…์„ ์ผ์น˜ ์‹œํ‚จ๋‹ค.
  1. int ๋ณด๋‹ค ์ž‘์€ ํฌ๊ธฐ์˜ ํ”ผ ์—ฐ์‚ฐ์ž๋“ค์€ int ํ˜•์œผ๋กœ ๋ณ€ํ™˜ํ•œ๋‹ค.
    • ์—ฐ์‚ฐ ์ค‘์˜ Overflow ๋ฐœ์ƒ ๊ฐ€๋Šฅ์„ฑ์„ ๋ง‰๊ธฐ ์œ„ํ•จ

 

๋ฐ˜์‘ํ˜•

+ Recent posts