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

  1. right click on project
  2. got build path -> configure build path
  3. click on libraries tab
  4. click add external jar , give path of mysql.jar

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -