Lỗi connect database, xa xưa nhưng gây lỗi 500

Đăng bởi admin lúc December 10th, 2009 - trong chuyên mục Lập trình

Tối đẹp trời này tớ đã bị mắc lỗi này và mất cả tiếng đồng hồ ngồi gãi đầu, mãi mới nhớ ra.

HTTP Status 500 -


type Exception report

message

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

exception

java.lang.NullPointerException

Đây là dòng báo lỗi của em nó.

Và nguyên nhân là do trong lớp connectDB thiếu 1 dòng.

Trước là như vầy:

Connection connection = null;
try {
connection = DriverManager.getConnection(“jdbc:postgresql://localhost:5432/caxxx”,”postgres”,”xxxxxx”);
} catch (Exception e) {}
return connection;

Và sửa lại như thế này để chạy bình thường:

Connection connection = null;
try {
Class.forName(“org.postgresql.Driver”);
connection = DriverManager.getConnection(“jdbc:postgresql://localhost:5432/caxxxx”,”postgres”,”xxxxxx”);
} catch (Exception e) {}
return connection;

One Response

  1. canary says:

    thì ra là thiếu có mỗi dòng đó làm anh suy nghĩ ,kakakka

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

© Mr.Cam update from iFeature(Cyberchimps)