본문 바로가기
비트 장기/spring

kk

by woohyun22 2018. 8. 20.



테이블 만들때 확실하게 만들었는지
@Controller 적었는지
@RequestMapping("t27") 괄호안에 알맞게 넣었는지




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<html>
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <%@ page import="java.util.*, java.text.*"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
    <!-- 이게 있어야 jstl쓸수있음. -->
<head>
<title>메인 페이지</title>
</head>
<body>
        <%=new Date()%><!-- 갱신이 안되고있을때를 확인하기 위해서 -->
        <h2>Hello World</h2>
     <a href="t24">링크24</a>
     <a href="t25">링크25</a>
     <a href="t26">링크26</a>
     <form action="t27">
    이름 : <input type = "text" name = "name"  ><br>
    나이 : <input type = "number" name = "age" ><br>
    고향: <input type = "text" name = "home"  ><br>
    연봉 : <input type = "number" name = "salary" ><br>
    <input type="submit"><br>
 <!-- <form action="t28">
     이름 : <input type = "text" name = "name"  ><br>
   연봉 : <input type = "number" name = "salary2" ><br>
    <input type="submit"><br>
    <form action="t29">
    이름 : <input type = "text" name = "name"  ><br> 
    <input type="submit"><br>
        <form action="t30">
    이름 : <input type = "text" name = "name"  ><br> 
    <input type="submit"><br> -->
</body>
</html>
cs





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package Pack01;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.LinkedList;
 
import javax.security.auth.message.callback.PrivateKeyCallback.Request;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
 
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
 
public class Tiger {
    @RequestMapping("t24")
    String func24(Model model) {
        System.out.println("24번째");
        Coffee coffee = new Coffee("홍길동",400);
        model.addAttribute("Coffee",coffee);
        return "LionView";
    }
    @RequestMapping("t25")
    String func25(Model model) {
        Coffee[] ar = new Coffee[4];
        ar[0]=new Coffee("김유신",100);
        ar[1]=new Coffee("김유신1",200);
        ar[2]=new Coffee("김유신2",300);
        ar[3]=new Coffee("김유신3",400);
        model.addAttribute("ar",ar);
        return "LionView";
    }
    @RequestMapping("t26")
    String func26(Model model) {
        LinkedList<Coffee> li = new LinkedList<>();
        li.add(new Coffee("김유신",100));
        li.add(new Coffee("김유신",100));
        li.add(new Coffee("김유신",100));
        li.add(new Coffee("김유신",100));
        model.addAttribute("li",li);
        return "LionView";
    }
 
 
}
cs




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package Pack01;
 
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
 
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class insert {
    @RequestMapping("t27")
    String func27(String name, int age,String home, int salary) {
         try {
                //1단계 : class 확인
                //현재 찾고 싶은 클래스를 찾아준다.
                String driver = "oracle.jdbc.driver.OracleDriver";
                System.out.println(Class.forName(driver));
                //2단계 : 로그인
                Connection con = null;
                String dburl = "jdbc:oracle:thin:@127.0.0.1:1521:orcl";
                String username = "c##jwh";
                String password = "1";
                con = DriverManager.getConnection(dburl, username, password);
                //3단계: 쿼리문 작성 및 컴파일
                PreparedStatement ps = null;
                //String sql="INSERT into banana values('개나리',25,1000,'하회마을')";
     
                String sql = String.format("insert into banana values('%s',%d,'%s',%d)",name, age, home, salary);
                System.out.println(sql);
                ps = con.prepareStatement(sql);
                //4단계: 실행
                ps.executeUpdate(); //f5번 누른것과 같다.
                //5단계: 접속 종료
                ps.close();
            } catch (Exception e) {
     
                // TODO: handle exception
                e.printStackTrace();
            }
         return "LionView";
    }
}
 
cs



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package Pack01;
 
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
 
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
 
@Controller
public class select {
    @RequestMapping("t30")
    String func30(String name, int age,String home, int salary) {
        try {
            //1단계 : class 확인
            //현재 찾고 싶은 클래스를 찾아준다.
            String driver = "oracle.jdbc.driver.OracleDriver";
            System.out.println(Class.forName(driver));
            //2단계 : 로그인
            Connection con = null;
            String dburl = "jdbc:oracle:thin:@127.0.0.1:1521:orcl";
            String username = "c##jwh";
            String password = "1";
            con = DriverManager.getConnection(dburl, username, password);
            //3단계: 쿼리문 작성 및 컴파일
            PreparedStatement ps = null;
            //String sql="INSERT into banana values('개나리',25,1000,'하회마을')";
 
            String sql = String.format("select * FROM banana WHERE name = '%s' and salary= %d ",name,salary);
            System.out.println(sql);
            
            ps = con.prepareStatement(sql);
             ResultSet rs = ps.executeQuery();
             
             while (rs.next()) {
                 String n = rs.getString("name");
                 int a = rs.getInt("age");
                 int s = rs.getInt("salary");
                 String h = rs.getString("home");
                 System.out.println(n + " " + " " + a + " " + s + " " + h);
             }
            //4단계: 실행
            ps.executeUpdate(); //f5번 누른것과 같다.
            //5단계: 접속 종료
            ps.close();
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }
        return "LionView";
    }
}
cs



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package Pack01;
 
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
 
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class delete {
    @RequestMapping("t29")
    String func29(String name) {
         try {
                //1단계 : class 확인
                //현재 찾고 싶은 클래스를 찾아준다.
                String driver = "oracle.jdbc.driver.OracleDriver";
                System.out.println(Class.forName(driver));
                //2단계 : 로그인
                Connection con = null;
                String dburl = "jdbc:oracle:thin:@127.0.0.1:1521:orcl";
                String username = "c##jwh";
                String password = "1";
                con = DriverManager.getConnection(dburl, username, password);
                //3단계: 쿼리문 작성 및 컴파일
                PreparedStatement ps = null;
                //String sql="INSERT into banana values('개나리',25,1000,'하회마을')";
     
                String sql = String.format("delete from banana where name = '%s'",name);
                System.out.println(sql);
                ps = con.prepareStatement(sql);
                //4단계: 실행
                ps.executeUpdate(); //f5번 누른것과 같다.
                //5단계: 접속 종료
                ps.close();
            } catch (Exception e) {
     
                // TODO: handle exception
                e.printStackTrace();
            }
         return "LionView";
    }
}
 
cs



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package Pack01;
 
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
 
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class update {
    @RequestMapping("t28")
    String func28(String name, int age,String home, int salary,int salary2) {
         try {
                //1단계 : class 확인
                //현재 찾고 싶은 클래스를 찾아준다.
                String driver = "oracle.jdbc.driver.OracleDriver";
                System.out.println(Class.forName(driver));
                //2단계 : 로그인
                Connection con = null;
                String dburl = "jdbc:oracle:thin:@127.0.0.1:1521:orcl";
                String username = "c##jwh";
                String password = "1";
                con = DriverManager.getConnection(dburl, username, password);
                //3단계: 쿼리문 작성 및 컴파일
                PreparedStatement ps = null;
                //String sql="INSERT into banana values('개나리',25,1000,'하회마을')";
     
                String sql = String.format(
                        "update banana set salary = %d,age = %d,salary = %d,home = '%s'where name = '%s'", 
                         age, salary, home, name);
                System.out.println(sql);
                ps = con.prepareStatement(sql);
                //4단계: 실행
                ps.executeUpdate(); //f5번 누른것과 같다.
                //5단계: 접속 종료
                ps.close();
            } catch (Exception e) {
     
                // TODO: handle exception
                e.printStackTrace();
            }
         return "LionView";
    }
}
 
cs


728x90

'비트 장기 > spring' 카테고리의 다른 글

jsp 로그인창 + session활용  (0) 2018.08.22
8/18 복습  (0) 2018.08.21
8/20  (0) 2018.08.20
8/17 jsp  (0) 2018.08.17
xml  (0) 2018.08.13

댓글