Netbeans 7.2에서이 오류가 발생했습니다. ClassNotFoundexception 및 InstantationException이 발생합니다. 나는이 문제에 정말로 붙어있다. 친절하게 도와주세요.Class.forName ("com.mysql.jdbc.Driver"). newInstance()
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
String driver = "com.mysql.jdbc.Driver";
con = null;
String username = "";
String password = "";
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/dbName", "root", "password");
Statement st = con.createStatement();
ResultSet mar = st.executeQuery("SELECT * FROM table");
Gson gson = new GsonBuilder().create();
response.setContentType("application/json");
response.setCharacterEncoding("utf-8");
} catch (SQLException e) {
String message = e.getMessage();
}
먼저, .newInstance() 호출이 필요 없다. 둘째,'mysql-connector.jar'를'WEB-INF/lib'에 추가하여 classpath에 추가 했습니까? –
왜 .newInstance() ???? –
셋째, .forName() 호출이 필요하지 않습니다. 질문의 남은 부분은 많지 않습니다. – EJP