这是我的第一个jsp网络应用。我有一个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 添加到项目的libraries文件夹中。
附:我有java的基本知识和PHP的工作知识。
答案 0 :(得分:0)
您加载了错误的驱动程序。
变化:
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
为:
Class.forName("com.mysql.jdbc.Driver");