Home > Back-end >  Using Intellij Idea development, using JDBC to connect to the database in the doGet method of the se
Using Intellij Idea development, using JDBC to connect to the database in the doGet method of the se

Time:09-24

 public class test extends the HttpServlet {
Public void doGet (it the req, HttpServletResponse resp) throws ServletException, IOException {
System. The out. Println (" Hello Servlet ");
PrintWriter out=resp. GetWriter ();
Out.println (getData ());
out.flush();
out.close();
}

Protected void doPost (it the req, HttpServletResponse resp) throws ServletException, IOException {
System. The out. Println (" Hello Servlet POST ");
}

Public String getData () {
Try {
DBUtil DB=new DBUtil (" localhost ", "3306", "testDemo", "root", "123456");
DB. Connect2DB ();
List Data=https://bbs.csdn.net/topics/DB.selectSQL (" Select * from Student ");
JSONArray _json=JSONArray. FromObject (data);
Return _json. ToString ();
} the catch (Exception e) {
e.printStackTrace();
}
return null;
}

Public static void main (String [] args) {
DBUtil DB=new DBUtil (" www.flyingspace.cn ", "3306", "test", "lc", "123456");
DB. Connect2DB ();
List Data=https://bbs.csdn.net/topics/DB.selectSQL (" Select * from Student ");
JSONArray _json=JSONArray. FromObject (data);
System. The out. Println (_json);
}
}

CodePudding user response:

Using Intellij Idea development, in the doGet method of the servlet using JDBC to connect to the database is always can not find the database driver error, but in the main method to run, there is no problem, some people say that online to go through the database configuration Idea to solve, but I configuration or not ah,

CodePudding user response:

CodePudding user response:

CodePudding user response:

Add the jar 'no

CodePudding user response:

Solved not import in the artifacts

CodePudding user response:

Didn't find drivers, there is no import drive packages

CodePudding user response:

Not in server deployment jar package, create the folder in the WEB - under the INF lib, put the jars in the folder, redeploy can solve,
  • Related