You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by nobles <no...@yahoo.com> on 2014/05/12 21:20:08 UTC

derby can not set database property in the dir. provided

 I have a the following code to set Database system property  in the
user.home directory. the next code atempt to start the database from the
same directory. but cannot find the database. Then it throws and excemption.
bellow     public static Connection getJServerConnection(){           
Connection dbConnection = null;       String strUrl;          try {             
String[] IP = Inet4Address.getLocalHost().toString().split("/");         
strUrl = "jdbc:derby://"+IP[1]+":1515/Ml_JUDEDB;create=true";        
Properties props = new Properties();         props.put("user",
"jude1_0_user");         props.put("password", "jude1_0_password");        
dbConnection = DriverManager.getConnection(strUrl, props);         }
catch(SQLException sqle) {          sqle.printStackTrace();         } catch
(UnknownHostException ex) {             
Logger.getLogger(JConnect.class.getName()).log(Level.SEVERE, null, ex);         
}    return dbConnection;     }        public static void setDBSystemDir() {           
String userHomeDir = System.getProperty("user.home", ".");    String
systemDir = userHomeDir+"/.judeServer";   
System.setProperty("derby.system.home", systemDir);   
System.out.println("Dir:"+systemDir);      NetworkServerControl  server;             
try {            String[] IP =
Inet4Address.getLocalHost().toString().split("/");                        
server = new NetworkServerControl(Inet4Address.getByName(IP[1]),1515);            
server.start( null );            } catch (UnknownHostException ex) {           
Logger.getLogger(JConnect.class.getName()).log(Level.SEVERE, null, ex);       
} catch (Exception ex) {           
Logger.getLogger(JConnect.class.getName()).log(Level.SEVERE, null, ex);       
}        }                 public static  void StartNetWorkServer(){                                 
setDBSystemDir();                   Connection connect =
getJServerConnection();                     System.out.println("CONNECT:    
"+connect);                }  java.sql.SQLNonTransientConnectionException:
java.net.ConnectException : Error connecting to server 127.0.0.1 on port
1515 with message Connection timed out: connect.CONNECT:     null



--
View this message in context: http://apache-database.10148.n7.nabble.com/derby-can-not-set-database-property-in-the-dir-provided-tp139192.html
Sent from the Apache Derby Developers mailing list archive at Nabble.com.

Re: derby can not set database property in the dir. provided

Posted by "Dag H. Wanvik" <da...@oracle.com>.
I reformatted this code as below, and it worked for me. Are you sure you 
have all the
derby jar files in the classpath?

It looks as if the server process didn't get started somehow. Can you 
see anything in derby.log?

Thanks,
Dag

I saw this when running the below program:

 > Dir:/home/dwanvik/.judeServer
 > CONNECT: org.apache.derby.client.net.NetConnection@28f2a10f


import java.net.Inet4Address;
import java.net.UnknownHostException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.derby.drda.NetworkServerControl;

public class foobar {

     public static void main(String[] args) throws Exception {
         StartNetWorkServer();
         Thread.sleep(2000);
         Connection c = getJServerConnection();
     }

     public static Connection getJServerConnection() {
         Connection dbConnection = null;
         String strUrl;
         try {
             String[] IP = 
Inet4Address.getLocalHost().toString().split("/");
             strUrl = "jdbc:derby://" + IP[1] + 
":1515/Ml_JUDEDB;create=true";
             Properties props = new Properties();
             props.put("user", "jude1_0_user");
             props.put("password", "jude1_0_password");
             dbConnection = DriverManager.getConnection(strUrl, props);
         } catch (SQLException sqle) {
             sqle.printStackTrace();
         } catch (UnknownHostException ex) {
             // 
Logger.getLogger(JConnect.class.getName()).log(Level.SEVERE, null, ex);
         }
         return dbConnection;
     }

     public static void setDBSystemDir() {
         String userHomeDir = System.getProperty("user.home", ".");
         String systemDir = userHomeDir + "/.judeServer";
         System.setProperty("derby.system.home", systemDir);
         System.out.println("Dir:" + systemDir);
         NetworkServerControl server;
         try {
             String[] IP = 
Inet4Address.getLocalHost().toString().split("/");
             server = new 
NetworkServerControl(Inet4Address.getByName(IP[1]), 1515);
             server.start(null);
         } catch (UnknownHostException ex) {
             // 
Logger.getLogger(JConnect.class.getName()).log(Level.SEVERE, null, ex);
         } catch (Exception ex) {
//Logger.getLogger(JConnect.class.getName()).log(Level.SEVERE, null, ex);
         }
     }

     public static void StartNetWorkServer() {
         setDBSystemDir();
         Connection connect = getJServerConnection();
         System.out.println("CONNECT: " + connect);
     }
}


On 12. mai 2014 21:20, nobles wrote:
> public static Connection getJServerConnection(){ Connection 
> dbConnection = null; String strUrl; try { String[] IP = 
> Inet4Address.getLocalHost().toString().split("/"); strUrl = 
> "jdbc:derby://"+IP[1]+":1515/Ml_JUDEDB;create=true"; Properties props 
> = new Properties(); props.put("user", "jude1_0_user"); 
> props.put("password", "jude1_0_password"); dbConnection = 
> DriverManager.getConnection(strUrl, props); } catch(SQLException sqle) 
> { sqle.printStackTrace(); } catch (UnknownHostException ex) { 
> Logger.getLogger(JConnect.class.getName()).log(Level.SEVERE, null, 
> ex); } return dbConnection; } public static void setDBSystemDir() { 
> String userHomeDir = System.getProperty("user.home", "."); String 
> systemDir = userHomeDir+"/.judeServer"; 
> System.setProperty("derby.system.home", systemDir); 
> System.out.println("Dir:"+systemDir); NetworkServerControl server; try 
> { String[] IP = Inet4Address.getLocalHost().toString().split("/"); 
> server = new NetworkServerControl(Inet4Address.getByName(IP[1]),1515); 
> server.start( null ); } catch (UnknownHostException ex) { 
> Logger.getLogger(JConnect.class.getName()).log(Level.SEVERE, null, 
> ex); } catch (Exception ex) { 
> Logger.getLogger(JConnect.class.getName()).log(Level.SEVERE, null, 
> ex); } } public static void StartNetWorkServer(){ setDBSystemDir(); 
> Connection connect = getJServerConnection(); 
> System.out.println("CONNECT: "+connect); }