이 질문은 이미 알고 있습니다. 불행히도 대답은 문제를 해결하는 데 도움이되지 않습니다.JSP를 사용하여 데이터베이스에 데이터를 삽입하는 방법
나는 데이터 (문자열 만)를 저장하는 "테스트"라는 MySQL 데이터베이스를 가지고있다. 다음 코드는 내 데이터를 가져 오는 내 <div>
-Conttainer를 보여줍니다.
<form action="index.jsp" method="POST">
<div .....>
<input type"text" name="termin" />
<input type="submit" value="submit" />
</div>
</form>
가 JSP 코드로 내가 사용 : 내가 클릭
<%
int result = 0;
String name = request.getParameter("termin");
Termin t1 = new Termin();
result = t1.setTermin(name);
%>
처음 제출 - 버튼, 내 Database.If에 NULL이 추가 내가 다른 시간을 클릭, 그것은 데이터베이스를 변경 나던.
누군가 어떤 일이 벌어지고 있는지 알 수 있습니까? 편집 : 내 잘못은 대신 데이터
public class Termin {
String URL = "jdbc:mysql://localhost:3306/test";
String username="root";
String pw = "root";
Connection con = null;
PreparedStatement stmt = null;
ResultSet res = null;
public Termin() {
try {
con = DriverManager.getConnection(URL,username,pw);
}catch(SQLException e) {
e.printStackTrace();
}
}
public int setTermin(String tname) {
int result = 0;
try {
stmt = con.prepareStatement(
"INSERT INTO ver(TName) VALUES(?);");
stmt.setString(1,tname);
result = stmt.executeUpdate();
stmt.clearParameters();
}catch(SQLException e) {
e.printStackTrace();
}
return result;
}
}
먼저 JSF 파일에서 Java 코드 (스크립틀릿)를 사용하지 말고 두 번째로 * Termin * 클래스의 코드를 게시하고 'name'을 (를) 사용하고있는 곳 –
아마도 여러분과 ' '이름'으로 아무것도하지 않니? 구현의 다른 부분을 보지 않고서는 하나만 추측 할 수 있습니다 ... – alfasin
Termin 클래스의 코드를 보여줄 수 있다면 좋을 것입니다. 다른 것은 쿼리에서 이름을 사용하고있는 곳입니다. –