mysql - Insert data to openfire database using java -
i using external mysql database openfire server , im trying insert data "openfire" named database , table name "ofuser" , fields columns "username" , "plainpassword","encryptedpassword","name","email","creationdate","modificationdate"
this code:
try{ class.forname("com.mysql.jdbc.driver"); //step 3: open connection system.out.println("connecting selected database..."); conn = drivermanager.getconnection(db_url, user, pass); system.out.println("connected database successfully..."); //step 4: execute query system.out.println("inserting records table..."); stmt = conn.createstatement(); string sql = "insert ofuser " + "values (100, 'zara', 'ali', 18)"; stmt.executeupdate(sql); sql = "insert ofuser " + "values (101, 'mahnaz', 'fatma', 25)"; stmt.executeupdate(sql); sql = "insert ofuser " + "values (102, 'zaid', 'khan', 30)"; stmt.executeupdate(sql); sql = "insert ofuser " + "values(103, 'sumit', 'mittal', 28)"; stmt.executeupdate(sql); system.out.println("inserted records table..."); }catch(sqlexception se){ //handle errors jdbc se.printstacktrace(); }catch(exception e){ //handle errors class.forname e.printstacktrace(); }finally{ //finally block used close resources try{ if(stmt!=null) conn.close(); }catch(sqlexception se){ }// nothing try{ if(conn!=null) conn.close(); }catch(sqlexception se){ se.printstacktrace(); }//end try }//end try system.out.println("goodbye!"); display("end of db"); }
and im running using eclipse. nothing happenes, wrong guys?
update:
im recieving error in console:
java.lang.classnotfoundexception: com.mysql.jdbc.driver @ java.net.urlclassloader$1.run(unknown source) @ java.net.urlclassloader$1.run(unknown source) @ java.security.accesscontroller.doprivileged(native method) @ java.net.urlclassloader.findclass(unknown source) @ java.lang.classloader.loadclass(unknown source) @ sun.misc.launcher$appclassloader.loadclass(unknown source) @ java.lang.classloader.loadclass(unknown source) @ java.lang.class.forname0(native method) @ java.lang.class.forname(unknown source) @ server$clientthread.<init>(server.java:236) @ server.start(server.java:74) @ servergui$serverrunning.run(servergui.java:132)
you have not included mysql.jar in class path.
follow following steps
- right click on project
- got build path -> configure build path
- click on libraries tab
- click add external jar , give path of mysql.jar
Comments
Post a Comment