웹으로 DB에 데이터 저장하기
[ 입력창 - inisert.html ]
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style type="text/css">
#regbox{ width : 300pxl }
#regbox{ display : block; width: 100px; float: left; }
</style>
</head>
<body>
<form method="post" action="insert.jsp">
<fieldset id="regbox">
<legend>Insert Data...</legend>
<label for="drone_id">drone id</label>
<input type="text" name="drone_id"/><br/>
<label for="dust_id">dust id</label>
<input type="text" name="dust_id"/><br/>
<label for="gps_id">gps id</label>
<input type="text" name="gps_id"/><br/>
<label for="chkpmValue">result</label>
<input type="number" step=any name="chkpmValue"/><br/>
<label for="pm25Value">std_result</label>
<input type="number" step=any name="pm25Value"/><br/>
<label for="pm10Value">std_result</label>
<input type="number" step=any name="pm10Value"/><br/>
<input type="submit" value="insert">
<input type="reset" value="cancel"/>
</fieldset>
</form>
</body>
</html>
<%@page import="java.text.DecimalFormat"%>
<%@page import="java.sql.*"%>
<%@page import="java.util.*"%>
<%@page import="org.json.JSONObject"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<head>
<body>
<%
request.setCharacterEncoding("utf-8");
String drone_id=request.getParameter("drone_id");
String dust_id=request.getParameter("dust_id");
String gps_id=request.getParameter("gps_id");
String chkpmValue=request.getParameter("chkpmValue");
String pm25Value=request.getParameter("pm25Value");
String pm10Value=request.getParameter("pm10Value");
//커넥션 선언
Connection con = null;
int n=0;
try {
//드라이버 호출, 커넥션 연결
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql?autoReconnect=true&useSSL=false", "ID", "PASSWD");
String query = "insert into dust(drone_id, dust_id, gps_id, chkpmValue, pm25Value, pm10Value, datecreated) values(?,?,?,?,?,?,now())";
PreparedStatement pstmt = con.prepareStatement(query);
pstmt=con.prepareStatement(query);
pstmt.setString(1,drone_id);
pstmt.setString(2,dust_id);
pstmt.setString(3,gps_id);
pstmt.setString(4,chkpmValue);
pstmt.setString(5,pm25Value);
pstmt.setString(5,pm10Value);
*직접 호출 방법 : http://localhost:8080/insert.jsp?drone_id=drone01&dust_id=dust01&gps_id=Eulgiro4ga&chkpmValue=18.444&pm25Value=22.473&pm10Value=27.987
[해당파일]
'Tech Story > IoT' 카테고리의 다른 글
구글차트 DB 연동하기 (1) | 2020.12.19 |
---|---|
라즈베리파이를 이용한 구글어시스턴트스피커 (16) | 2020.12.19 |
파이썬으로 공공데이터 API XML 파싱후 DB저장하기 (0) | 2018.06.18 |
MySQL 테이블 생성-기초 (0) | 2018.06.18 |
MySQL 접속테스트 (1) | 2018.06.18 |