java.sql.SQLException: No suitable driver found for jdbc:mysql:/localhost/XXX?还是没有解决
来源:互联网 发布:淘宝代购网店 注册 编辑:程序博客网 时间:2024/04/30 10:22
package servlet;
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Insert extends HttpServlet {
/**
* Constructor of the object.
*/
public Insert() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request
* the request send by the client to the server
* @param response
* the response send by the server to the client
* @throws ServletException
* if an error occurred
* @throws IOException
* if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print(" This is ");
out.print(this.getClass());
out.println(", using the GET method");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to
* post.
*
* @param request
* the request send by the client to the server
* @param response
* the response send by the server to the client
* @throws ServletException
* if an error occurred
* @throws IOException
* if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
boolean flag;
try {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
System.out.println("驱动包加载失败。");
System.exit(0);
}
// 建立与数据库的连接
Connection con=DriverManager.getConnection("jdbc:mysql:/localhost/org.lyy"
,"root","123456");
// 发送语句
Statement stmt = con.createStatement();
request.setCharacterEncoding("UTF-8");
String SID = request.getParameter("SID");
String SName = request.getParameter("SName");
String SSex = request.getParameter("SSex");
String SNum = request.getParameter("SNum");
String SPhone = request.getParameter("SPhone");
String SSubject = request.getParameter("SSubject");
String SCollege = request.getParameter("SCollege");
String PlaceOfBirth = request.getParameter("PlaceOfBirth");
String SPhoto = request.getParameter("SPhoto");
String sql = "select * from Student where SID='" + SID + "'";
ResultSet rs = stmt.executeQuery(sql);
if (rs.next()) {
flag = false;
} else {
sql = "INSERT INTO Student(SID,SName,SSex,SNum ,SPhone,SSubject,SCollege,PlaceOfBirth,SPhoto) "
+ "VALUES ('"
+ SID
+ "','"
+ SName
+ "','"
+ SSex
+ "','"
+ SNum
+ "','"
+ SPhone
+ "','"
+ SSubject
+ "','"
+ SCollege
+ "','"
+ PlaceOfBirth
+ "','"
+ SPhoto + "')";
// 更新数据库,每一次对数据库进行操作后,都记得更新数据库;
stmt.executeUpdate(sql);
flag = true;
}
response.setContentType("text/html;charset=UTF-8"); // 定义页面显示类型与编码方式
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>添加成功</TITLE>");
out.println("</HEAD>");
out.println(" <BODY>");
out.println("<h4>");
if (flag == true) {
out.println("添加成功,可以继续添加... ...");
String trans = "<meta http-equiv=\"Refresh\" content=\"2;url=../InsertStudent.jsp\">";
out.println(trans);
} else {
out.println("添加的用户已经存在,请重新添加... ...");
String trans = "<meta http-equiv=\"Refresh\" content=\"2;url=../InsertStudent.jsp\">";
out.println(trans);
}
out.println("</h4>");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
// 记住要close掉创建的对象和顺序
stmt.close();
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException
* if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Insert extends HttpServlet {
/**
* Constructor of the object.
*/
public Insert() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request
* the request send by the client to the server
* @param response
* the response send by the server to the client
* @throws ServletException
* if an error occurred
* @throws IOException
* if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print(" This is ");
out.print(this.getClass());
out.println(", using the GET method");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to
* post.
*
* @param request
* the request send by the client to the server
* @param response
* the response send by the server to the client
* @throws ServletException
* if an error occurred
* @throws IOException
* if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
boolean flag;
try {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
System.out.println("驱动包加载失败。");
System.exit(0);
}
// 建立与数据库的连接
Connection con=DriverManager.getConnection("jdbc:mysql:/localhost/org.lyy"
,"root","123456");
// 发送语句
Statement stmt = con.createStatement();
request.setCharacterEncoding("UTF-8");
String SID = request.getParameter("SID");
String SName = request.getParameter("SName");
String SSex = request.getParameter("SSex");
String SNum = request.getParameter("SNum");
String SPhone = request.getParameter("SPhone");
String SSubject = request.getParameter("SSubject");
String SCollege = request.getParameter("SCollege");
String PlaceOfBirth = request.getParameter("PlaceOfBirth");
String SPhoto = request.getParameter("SPhoto");
String sql = "select * from Student where SID='" + SID + "'";
ResultSet rs = stmt.executeQuery(sql);
if (rs.next()) {
flag = false;
} else {
sql = "INSERT INTO Student(SID,SName,SSex,SNum ,SPhone,SSubject,SCollege,PlaceOfBirth,SPhoto) "
+ "VALUES ('"
+ SID
+ "','"
+ SName
+ "','"
+ SSex
+ "','"
+ SNum
+ "','"
+ SPhone
+ "','"
+ SSubject
+ "','"
+ SCollege
+ "','"
+ PlaceOfBirth
+ "','"
+ SPhoto + "')";
// 更新数据库,每一次对数据库进行操作后,都记得更新数据库;
stmt.executeUpdate(sql);
flag = true;
}
response.setContentType("text/html;charset=UTF-8"); // 定义页面显示类型与编码方式
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>添加成功</TITLE>");
out.println("</HEAD>");
out.println(" <BODY>");
out.println("<h4>");
if (flag == true) {
out.println("添加成功,可以继续添加... ...");
String trans = "<meta http-equiv=\"Refresh\" content=\"2;url=../InsertStudent.jsp\">";
out.println(trans);
} else {
out.println("添加的用户已经存在,请重新添加... ...");
String trans = "<meta http-equiv=\"Refresh\" content=\"2;url=../InsertStudent.jsp\">";
out.println(trans);
}
out.println("</h4>");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
// 记住要close掉创建的对象和顺序
stmt.close();
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException
* if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
网上貌似没有正确的
0 0
- java.sql.SQLException: No suitable driver found for jdbc:mysql:/localhost/XXX?还是没有解决
- android studio下解决 java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/
- mondrian java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/foodmart
- java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/airline
- java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/
- java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/
- java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/
- java.sql.SQLException: No suitable driver found for jdbc:mysql
- java.sql.SQLException: No suitable driver found for jdbc:mysql
- 调试经验-java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:@localhost:1521:orcl
- java.sql.SQLException: No suitable driver found for jdbc:sqlserver://localhost:1433;databaseName
- java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:@localhost:1521:ORCL
- java.sql.SQLException: No suitable driver found for jdbc:derby
- SQLException:No suitable driver found for jdbc:myqsl://localhost/......
- java.sql.SQLException: No suitable driver found for jdbc:microsoft:sqlserver://127.0.0.1:1433;解决
- Jmeter java.sql.SQLException: No suitable driver found for jdbc:mysql:
- No suitable driver found for jdbc:mysql://localhost/mysql
- java.sql.SQLException:No suitable driver found for http://localhost:3306/school
- 数据处理小例子
- 自动生成Android ContentProvider、Database相关代码
- 我们都一样
- socket 相关命令
- 坎贤视匈怪揖良兴逝阑
- java.sql.SQLException: No suitable driver found for jdbc:mysql:/localhost/XXX?还是没有解决
- windows下游戏服务器端框架Firefly安装说明及demo运行
- 用svn管理项目时,复制文件的注意事项
- NBA总决赛第三战:热火主场取胜 扩大领先优势
- DM8168 PWM驱动与测试程序
- 正则表达式
- CursorAdapter类的使用
- 解决:LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
- Java Socket收发异步长连接