database - How to fix "No suitable driver found for jdbc:mysql://localhost:3306/emp"? -
this first jsp web app. have html page posts info received jsp page.
machine stats:
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
environment variables:
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 , 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 code:
<%@ 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 registration (id, ignoualr, enrlno, firstname, middlename, lastname, ffirstname, fmiddlename, flastname, dob, sex, progc, address, state, city, district, pincode, mobileno) values (null"; (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>
also, added mysql-connector-java-5.0.8.zip libraries folder of project.
p.s. have basic knowledge of java , working knowledge of php.
you load wrong driver.
change:
class.forname("sun.jdbc.odbc.jdbcodbcdriver");
to:
class.forname("com.mysql.jdbc.driver");
Comments
Post a Comment