java - Cannot call Method in JDBC file from Servlet file -
public class jdbc_pro extends helloworld { //database essential public string jdbc_driver = "com.mysql.jdbc.driver"; public string db_url = "jdbc:mysql://localhost:3306/kalinga"; public string user = "root"; public string pass = "welcome123"; public connection con = null ; public jdbc_pro(){ jdbc_driver = "com.mysql.jdbc.driver"; db_url = "jdbc:mysql://localhost:3306/kalinga"; user = "root"; pass = "welcome123"; try{ class.forname(jdbc_driver); //system.out.println("connecting database"); con = drivermanager.getconnection(db_url, user, pass); } catch(exception e){system.out.println(e); } } public void insertdata(string state,string city,string age,string dep,string person,string amount,string des){ try{ string sql ="insert kan values(?,?,?,?,?,?,?)"; preparedstatement pst = con.preparestatement(sql); pst.setstring(1,state); pst.setstring(2, city); pst.setstring(3, age); pst.setstring(4, dep); pst.setstring(5, person); pst.setstring(6, amount); pst.setstring(7, des); int numrowschanged = pst.executeupdate(); system.out.println(numrowschanged); pst.close(); con.close(); }catch(exception e){ e.printstacktrace();} }
abov jdbc file ... want call method insertdata() servlet file . when run jdbc file alone the data getting updated table when call method servlet file like
jdbc_pro b = new jdbc_pro(); b.insertdata("the arguments goes here..");
exception
java.lang.classnotfoundexception: com.mysql.jdbc.driverjava.lang.nullpointerexception
both files in same package! can please solve problem
have added mysql connector jar in project?
i guess missing mysql connector jar throwing exception
java.lang.classnotfoundexception: com.mysql.jdbc.driverjava.lang.nullpointerexception
Comments
Post a Comment