java - How to configure javadb in eclipse(part2)? -


this continuation of previous question how configure javadb in eclipse?. able made changes on code giving me error -> error: java.net.connectexception : error connecting server localhost on port 1527 message connection refused: connect. hope guys can me one.

here code:

import java.sql.connection; import java.sql.drivermanager; import java.sql.resultset; import java.sql.statement;  public class test {  public static void main(string[] args) {     try {         class.forname("org.apache.derby.jdbc.clientdriver").newinstance();     } catch (instantiationexception e) {         e.printstacktrace();     } catch (illegalaccessexception e) {         e.printstacktrace();     } catch (classnotfoundexception e) {         e.printstacktrace();     }      final string db_url = "jdbc:derby://localhost:1527/coffeedb;create=true";      try{         connection conn = drivermanager.getconnection(db_url);         statement stmt = conn.createstatement();          string sql = ("create table coffee(description char(25),prodnum char(10) not null primary key,price double)");         stmt.execute(sql);          sql = "insert coffee values('bolivian dark','14-001',8.95)";         stmt.executeupdate(sql);          sql = "insert coffee values('bolivian medium','14-002',8.95)";         stmt.executeupdate(sql);          sql = "insert coffee values('brazilian dark','15-001',7.95)";         stmt.executeupdate(sql);          sql = "insert coffee values('brazilian medium','15-002',7.95)";         stmt.executeupdate(sql);          sql = "insert coffee values('brazilian decaf','15-003',8.55)";         stmt.executeupdate(sql);          sql = "insert coffee values('central american dark','16-001',9.95)";         stmt.executeupdate(sql);          sql = "insert coffee values('central american medium','16-002',9.95)";         stmt.executeupdate(sql);          sql = "insert coffee values('sumatra dark','17-001',7.95)";         stmt.executeupdate(sql);          sql = "insert coffee values('sumatra decaf','17-002',8.95)";         stmt.executeupdate(sql);          sql = "insert coffee values('sumatra medium','17-003',7.95)";         stmt.executeupdate(sql);          sql = "insert coffee values('sumatra organic dark','17-004',11.95)";         stmt.executeupdate(sql);          sql = "insert coffee values('kona medium','18-001',18.45)";         stmt.executeupdate(sql);          sql = "insert coffee values('kona dark','18-002',18.45)";         stmt.executeupdate(sql);          sql = "insert coffee values('french roast dark','19-001',9.65)";         stmt.executeupdate(sql);          sql = "insert coffee values('galapagos medium','20-001',6.85)";         stmt.executeupdate(sql);          sql = "insert coffee values('guatemalan dark','21-001',9.95)";         stmt.executeupdate(sql);          sql = "insert coffee values('guatemalan decaf','21-002',10.45)";         stmt.executeupdate(sql);          sql = "insert coffee values('guatemalan medium','21-003',9.95)";         stmt.executeupdate(sql);          string sqlstatement = "select description coffee";         resultset result = stmt.executequery(sqlstatement);          system.out.println("coffees found in database");         system.out.println("-----------------------------");          while(result.next()){             system.out.println(result.getstring("description"));         }          conn.close();     }catch(exception ex){         system.out.println("error: " + ex.getmessage());     }  }  } 

i had been trying current code , found exception happens when server not being started. way solve start server in simple way:

go lib folder in extracted folder of derby server download on command prompt. me follows:

c:\>cd opt\db-derby-10.11.1.1-lib\lib  c:\opt\db-derby-10.11.1.1-lib\lib>java -jar derbyrun.jar server start sat oct 03 16:26:29 ist 2015 : security manager installed using basic server security policy. sat oct 03 16:26:29 ist 2015 : apache derby network server - 10.11.1.1 - (1616546) started , ready accept connections on port 1527 

there different way can start server in eclipse. need install plugin , start server. following references should you:

derby plugin how to
getting started derby plugin eclipse


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -