gpt4 book ai didi

mysql - 如何修复 "No suitable driver found for jdbc:mysql://localhost:3306/emp"?

转载 作者:行者123 更新时间:2023-11-29 23:27:12 25 4
gpt4 key购买 nike

这是我的第一个 jsp Web 应用程序。我有一个 html 页面,其中发布了 jsp 页面接收的一些信息。

机器统计:

64bit machine Windows 7  
64bit Netbeans 8.1
64bit Java - jdk1.7.0_55, jdk1.8.0_05
32bit Java - none
64bit Jre - jre8
32bit Jre - jre1.8.0_25

环境变量:

CLASSPATH - .;C:\PROGRA~2\IBM\SQLLIB\java\db2java.zip;C:\PROGRA~2\IBM\SQLLIB\java\db2jcc.jar;C:\PROGRA~2\IBM\SQLLIB\java\db2jcc_license_cu.jar;C:\PROGRA~2\IBM\SQLLIB\bin;%JAVA_HOME7%\jre\lib;E:\All Softwares\Programming Languages And Tools\mysql-connector-java-5.0.8.zip

JAVA_HOME - C:\Program Files\Java\jdk1.7.0_55\
JAVA_HOME8 - C:\Program Files\Java\jdk1.8.0_05\
JRE_HOME - C:\Program Files\Java\jre7\
JRE_HOME8 - C:\Program Files\Java\jre8\
Path - C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Windows Resource Kits\Tools\;C:\Program Files\Dell\DW WLAN Card;C:\Program Files (x86)\AMD APP\bin\x86_64;C:\Program Files (x86)\AMD APP\bin\x86;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Common Files\Adobe\AGL;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files\WIDCOMM\Bluetooth Software\;C:\Program Files\WIDCOMM\Bluetooth Software\syswow64;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files (x86)\Microsoft SQL Server\100\DTS\Binn\;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\;%JAVA_HOME%bin\;C:\Program Files (x86)\Microsoft SQL Server\90\Tools\binn\;C:\PROGRA~2\IBM\SQLLIB\BIN;C:\PROGRA~2\IBM\SQLLIB\FUNCTION;C:\Program Files (x86)\Zend\MySQL55\bin;%JRE_HOME%

JSP代码:

    <%@ page import="java.sql.*" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
if (!"POST".equalsIgnoreCase(request.getMethod())) {
%>
<h1>Invalid Token!</h1>
<%
} else {
Connection connection = null;

String[] arr = new String[18];
arr[0] = (request.getParameter("ignoualr")!=null)?request.getParameter("ignoualr").toString():"0";
arr[1] = request.getParameter("enrlno").toString();
arr[2] = request.getParameter("firstname").toString();
arr[3] = request.getParameter("middlename").toString();
arr[4] = request.getParameter("lastname").toString();
arr[5] = request.getParameter("ffirstname").toString();
arr[6] = request.getParameter("fmiddlename").toString();
arr[7] = request.getParameter("flastname").toString();
arr[8] = request.getParameter("dob").toString();
arr[9] = (request.getParameter("sex")!=null)?request.getParameter("sex").toString():"0";
arr[10] = request.getParameter("progc").toString();
arr[11] = request.getParameter("address").toString();
arr[12] = request.getParameter("state").toString();
arr[13] = request.getParameter("city").toString();
arr[14] = request.getParameter("district").toString();
arr[15] = request.getParameter("pincode").toString();
arr[16] = request.getParameter("mobileno").toString();
arr[17] = request.getParameter("submit").toString();

if(arr[17].equalsIgnoreCase("Submit")) {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/emp", "root", "");

Statement statement = connection.createStatement();
String command = "INSERT INTO registration (id, ignoualr, enrlno, firstname, middlename, lastname, ffirstname, fmiddlename, flastname, dob, sex, progc, address, state, city, district, pincode, mobileno) VALUES (null";

for (int i=0; i<17; i++)
command = command + ", '" + arr[i] + "'";
command = command + ")";
statement.executeUpdate(command);
%>
<h1>Hello World!</h1>
<%
} else {
%>
<h1>Invalid Token!</h1>
<%
}
}
%>
</body>
</html>

此外,我将mysql-connector-java-5.0.8.zip添加到项目的库文件夹中。
附:我有java基础知识和PHP工作知识。

最佳答案

您加载了错误的驱动程序。

更改:

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

至:

Class.forName("com.mysql.jdbc.Driver");

关于mysql - 如何修复 "No suitable driver found for jdbc:mysql://localhost:3306/emp"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26865441/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com