JSP+Mysql 게시판만들기 에러..부탁드려요.

JSP+Mysql 게시판만들기 에러..부탁드려요.

작성일 2008.01.17댓글 1건
    게시물 수정 , 삭제는 로그인 필요

원래 오라클db를 사용한 소스인데 mysql로 변경하려고 합니다.

 

톰캣에러는 다음과 같습니다.

HTTP Status 500 -


type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP: JSP FileName:/jsp_example/write.jspJava FileName:/C:/tomcat5_5/work/Catalina/localhost/_//org/apache/jsp/jsp_005fexample\write_jsp.javaAn error occurred at line: 12 in the jsp file: /jsp_example/write.jspSyntax error on token "thorws", throws expected9: 	return conn;10: }11: 12: String TO_DB(String str)thorws Exception13: {14: 	if(str==null)15: 	{JSP FileName:/jsp_example/write.jspJava FileName:/C:/tomcat5_5/work/Catalina/localhost/_//org/apache/jsp/jsp_005fexample\write_jsp.javaAn error occurred at line: 10 in the jsp file: /jsp_example/write.jspSyntax error on token "}", delete this token7: 	Class.forName("org.gjt.mm.mysql.Driver").newInstance();8: 	Connection conn=DriverManager.getConnection(url,"root","1234");9: 	return conn;10: }11: 12: String TO_DB(String str)thorws Exception13: {JSP FileName:/jsp_example/write.jspJava FileName:/C:/tomcat5_5/work/Catalina/localhost/_//org/apache/jsp/jsp_005fexample\write_jsp.javaAn error occurred at line: 54 in the jsp file: /jsp_example/write.jspSyntax error, insert "}" to complete MethodBody51: 		"','"+description+"')";52: 	stmt.executeUpdate(sql);53: 	stmt.close();54: }catch(SQLException e){55: }56: %>57: <html>JSP FileName:/jsp_example/write.jspJava FileName:/C:/tomcat5_5/work/Catalina/localhost/_//org/apache/jsp/jsp_005fexample\write_jsp.javaAn error occurred at line: 54 in the jsp file: /jsp_example/write.jspSyntax error, insert "Finally" to complete TryStatement51: 		"','"+description+"')";52: 	stmt.executeUpdate(sql);53: 	stmt.close();54: }catch(SQLException e){55: }56: %>57: <html>Stacktrace:	org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:98)	org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)	org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:435)	org.apache.jasper.compiler.Compiler.compile(Compiler.java:298)	org.apache.jasper.compiler.Compiler.compile(Compiler.java:277)	org.apache.jasper.compiler.Compiler.compile(Compiler.java:265)	org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:564)	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:302)	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

note The full stack trace of the root cause is available in the Apache Tomcat/5.5.25 logs.

 

전체소스는 다음과 같습니다.

%@ page contentType="text/html;charse=euc-kr"%>
<%@ page language="java" import="java.sql.*,java.util.*,javax.servlet.http.*" %>
<%!
Connection DB_Connection()throws ClassNotFoundException,SQLException,Exception
{
 String url="jdbc:mysql://localhost:8080/board";
 Class.forName("org.gjt.mm.mysql.Driver").newInstance();
 Connection conn=DriverManager.getConnection(url,"root","1234");
 return conn;
}

String TO_DB(String str)thorws Exception
{
 if(str==null)
 {
 return null;
 }
 return new String(str.getBytes("8859_1"),"KSC5601");
}
%>
<%!
Connection conn=DB_Connection();
Statement stmt=null;

String user_name=request.getParameter("user_name");
user_name=TO_DB(user_name);
String passwd=request.getParameter("passwd");
String type=request.getParameter("type");
String title=request.getParameter("title");
title=TO_DB(title);
String e_mail=request.getParameter("e_mail");
String home_url=request.getParameter("home_url");
String description=request.getParameter("description");
description=TO_DB(description);

try{
 stmt=conn.createStatement();

 String sql="insert into board(articleid, "+
  "title,user_name,write_date,type,e_mail,home_url,"+
  "hits,passwd,description)"+
  "values(seq_board.nextval"+
  ",'"+title+
  "','"+user_name+
  "',sysdate"+
  ",'"+type+
  "','"+e_mail+
  "','"+home_url+
  "',0"+
  ",'"+passwd+
  "','"+description+"')";
 stmt.executeUpdate(sql);
 stmt.close();
}catch(SQLException e){
}
%>
<html>
<head>
<script language="javascript">
function alrim(){
 alert("성공적으로 등록하였습니다.")
 //location.href="list.jsp";
}
</script>
</head>
<body onload="alrim();">
</body>
</html>

 



profile_image 익명 작성일 -

An error occurred at line: 12 in the jsp file: /jsp_example/write.jsp
Syntax error on token "thorws", throws expected
9: return conn;
10: }
11:
12: String TO_DB(String str)thorws Exception
13: {
14: if(str==null)
15: {

thorws -> throws 로 변경해주시면 해결 될 겁니다.


JSP FileName:/jsp_example/write.jsp
Java FileName:/C:/tomcat5_5/work/Catalina/localhost/_//org/apache/jsp/jsp_005fexample\write_jsp.java

An error occurred at line: 10 in the jsp file: /jsp_example/write.jsp
Syntax error on token "}", delete this token
7: Class.forName("org.gjt.mm.mysql.Driver").newInstance();
8: Connection conn=DriverManager.getConnection(url,"root","1234");
9: return conn;
10: }
11:
12: String TO_DB(String str)thorws Exception
13: {


JSP FileName:/jsp_example/write.jsp
Java FileName:/C:/tomcat5_5/work/Catalina/localhost/_//org/apache/jsp/jsp_005fexample\write_jsp.java

An error occurred at line: 54 in the jsp file: /jsp_example/write.jsp
Syntax error, insert "}" to complete MethodBody
51: "','"+description+"')";
52: stmt.executeUpdate(sql);
53: stmt.close();
54: }catch(SQLException e){
55: }
56: %>
57: <html>

이것은 선언부를 <%! 로 하셨네요 이것을 <% 로 바꾸어주세요

<%! -> <%
Connection conn=DB_Connection();
Statement stmt=null;

String user_name=request.getParameter("user_name");
user_name=TO_DB(user_name);


JSP FileName:/jsp_example/write.jsp
Java FileName:/C:/tomcat5_5/work/Catalina/localhost/_//org/apache/jsp/jsp_005fexample\write_jsp.java

An error occurred at line: 54 in the jsp file: /jsp_example/write.jsp
Syntax error, insert "Finally" to complete TryStatement
51: "','"+description+"')";
52: stmt.executeUpdate(sql);
53: stmt.close();
54: }catch(SQLException e){
55: }
56: %>
57: <html>

try-catch-finally 에서 finally 를 선언하라고 그러는 건데..

꼬옥 선언은 안해도 될텐데.

통상 finally 구현하면 거기에 있는 로직은 try-catch 로 종료가 되어도 꼭 수행해야할 로직을 넣습니다.

여기서는

Connection conn=DB_Connection();
Statement stmt=null;

위 두개를 종료시켜주는 로직을 추가하시면 되겠네요.

finally {

    if ( stmt != null ) try {stmt.close();} catch (SQLException e) {}

    if ( conn != null ) try {conn.close();} catch (SQLException e) {}

}

 

위 로직은 db connection의 autocommit() 기능을 기본 설정으로 사용하고 계시네요.

추후에는

conn.setAutoCommit(false) 로 하신 후

int cnt = stmt.executeUpdate(sql);

if ( cnt == 1) 처리되어야 할 건이 1건일 경우

    conn.commit();

else

    conn.rollback();

 

catch 문에도 conn.rollback() 기능을 적용해줘야 합니다.

그리고 conn.close() 전에 conn.setAutoCommit(true) 로 다시 전환해줘야 하구요.


 

 

 

jsp+mysql 게시판 에러??

... 근데 아래와 같은 에러가 발생합니다.... getConnection(Unknown Source) java.sql.DriverManager.getConnection(Unknown Source) org.apache.jsp....

jsp mysql 동빈나 게시판 만들기 4강

https://www.youtube.com/watch?v=RYo3OGlRoJw&list=PLRx0vPvlEmdAZv_okJzox5wj2gG_fNh_6&index=4 강의 주소입니당 11:00부터 시작하는 데 1.번 사진 mysql-connector-java-5.1.42-bin.jar를 lib에...

jsp mysql연동시 에러입니다.

게시판을 떠와서 작업을 할려구하는데... ^^꼭좀 부탁드립니다. [javac] C:\Program... jsp mysql연동시 에러가 아닙니다...

mysql 게시판 만들기 오류

... charset=EUC-KR" pageEncoding="EUC-KR"%> JSP 게시판 웹 사이트... import java.sql.Connection; import java.sql.DriverManager; import java.sql....

JSP 게시판 만들기 에러 질문

... 우선 에러 내용을 보니 흔히 접하는 NullPointerException 에러입니다. listView.jsp 의 23번 라인에 plist.getCurrentPage() 부분인 것 같습니다. 아마 plist 가...

mysql jdbc를 이용한 게시판 질문

jsp를 이용해 게시판을 만드는데 jsp페이지에서 자바빈즈 사용하고 자바빈즈에서는... 지금 에러는 Null값이 발생해서 그렇습니다. 그리고 getBoardList() 메서드 호출시...

PHP와 MySQL 로 게시판 만들기

... PHP과 MySQL을 사용해서 게시판 만들기 강좌나 예제로 배워볼수 있는 사이트... 답변 부탁드립니다.~! http://obst.new21.net/ OBST 라고 함수 정보가 많은곳 http...