maven project -> create x -> maven-archetype-webapp ->위에 두개이름적고 finish
webapp = webcontent ->미리 index 생성되어있음
project alt+enter ->project facets -> runtimes ->tomcat check ->apply ->apply close
컴파일-> utf-8 ->xml추가 ->alt+f5 -> 실행
내 계정이 있을시 cmd에서 create 테이블 생성 후 소스 실행시키면 안에 들어가있다.
index
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 | <h2>Hello World!</h2> <form action="aaa.jsp"> insert name : <input type="text" name="name"><br> age : <input type="text" name="age"><br> salary : <input type="text"name="salary"><br> home : <input type="text" name="home"><br> <input type="submit"><br> </form> <form action="bbb.jsp"> change name : <input type="text" name="name"><br> name2 : <input type="text" name="name2"><br> age : <input type="text" name="age"><br> salary : <input type="text"name="salary"><br> home : <input type="text" name="home"><br> <input type="submit"><br> </form> <form action="ccc.jsp"> delete name : <input type="text" name="name"><br> <input type="submit"><br> </form> <form action="ddd.jsp"> all age1 : <input type="text" name="age1"><br> <input type="submit"><br> </form> | cs |
aaa
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 | <% String name = request.getParameter("name"); int age = Integer.parseInt(request.getParameter("age")); int salary = Integer.parseInt(request.getParameter("salary")); String home = request.getParameter("home"); %> <% 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 = "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,%d,'%s')", name, age, salary, home); System.out.println(sql); ps = con.prepareStatement(sql); //4단계: 실행 ps.executeUpdate(); //f5번 누른것과 같다. //5단계: 접속 종료 ps.close(); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } System.out.println("호랑이"); %> 입력됨 <a href="index.jsp">다시 돌아가기</a> </body> | cs |
bbb
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 | <% String name = request.getParameter("name"); String name2 = request.getParameter("name2"); int age = Integer.parseInt(request.getParameter("age")); int salary = Integer.parseInt(request.getParameter("salary")); String home = request.getParameter("home"); %> <% 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 = "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 name = '%s',age = %d,salary = %d,home = '%s'where name = '%s'", name2, age, salary, home, name); //update문 System.out.println(sql); ps = con.prepareStatement(sql); //4단계: 실행 ps.executeUpdate(); //f5번 누른것과 같다. //5단계: 접속 종료 ps.close(); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } System.out.println("호랑이"); %> 바뀜 <a href="index.jsp">다시 돌아가기</a> | cs |
ccc
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 | <% String name = request.getParameter("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 = "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); //delete System.out.println(sql); ps = con.prepareStatement(sql); //4단계: 실행 ps.executeUpdate(); //f5번 누른것과 같다. //5단계: 접속 종료 ps.close(); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } System.out.println("호랑이"); %> 삭제됨 <a href="index.jsp">다시 돌아가기</a> | cs |
ddd
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 54 55 56 57 58 | <% int age1 = Integer.parseInt(request.getParameter("age1")); try { /* 2.접속 */ Connection con = null; String dburl = "jdbc:oracle:thin:@127.0.0.1:1521:orcl"; String username = "jwh"; String password = "1"; con = DriverManager.getConnection(dburl, username, password); /* 3.쿼리문 작성,컴파일 */ PreparedStatement ps = null; String sql = "select * from banana where age>=11"; ps = con.prepareStatement(sql); System.out.println(sql); %> <table border="1"> <%-- 이름: <%= n %><br/> 나이: <%= a %><br/> 월급: <%= s %><br/> 고향: <%= h %><br/> <br/> --%> <tr> <th><h1>이름</h1></th> <th><h1>나이</h1></th> <th><h1>월급</h1></th> <th><h1>고향</h1></th> </tr> <% 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); %> <tr> <th><%=n%></th> <th><%=a%></th> <th><%=s%></th> <th><%=h%></th> </tr> <% } //4.디벨로퍼 f5 역할 //5.commit과 같음(접속종료) rs.close(); rs.close(); con.close(); } catch (Exception e) { } %> 검색됨 <a href="index.jsp">다시 돌아가기</a> | cs |
728x90
댓글