NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

Iniciate JavaDB within the code

 
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users
View previous topic :: View next topic  
Author Message
Unleash



Joined: 19 Sep 2008
Posts: 12
Location: Brazil

PostPosted: Tue Mar 31, 2009 12:08 pm    Post subject: Iniciate JavaDB within the code Reply with quote

Hi !
I'm building a desktop database application, and i chose JavaDB as my database.
I've already done the connection to my database within the code, but i also want to inciate the JavaDB Server within the code.
How can i do that ?

Thanks !!
Back to top
Dhvanika Shah
Posted via mailing list.





PostPosted: Tue Mar 31, 2009 12:32 pm    Post subject: Iniciate JavaDB within the code Reply with quote

Why don't you create an xml file with <db_connection> tag or something
Where you store the connection url to connect to any db server ..

Is that what are you asking?

Regards,
Dhvani

--------------------------------------
Contact:
Email: address-removed
Skype: dhwanishahb
Mobile: 91-9601270483
---------------------------------------

-----Original Message-----
From: Unleash [mailto:address-removed]
Sent: Tuesday, March 31, 2009 5:39 PM
To: address-removed
Subject: [nbj2ee] Iniciate JavaDB within the code

Hi !

I'm building a desktop database application, and i chose JavaDB as my
database.

I've already done the connection to my database within the code, but i
also want to inciate the JavaDB Server within the code.

How can i do that ?



Thanks !!

------------------------
Brazilian Computer Engineering Student !
Back to top
Geertjan Wielenga
Posted via mailing list.





PostPosted: Tue Mar 31, 2009 12:47 pm    Post subject: Iniciate JavaDB within the code Reply with quote

Unleash wrote:
Quote:
Hi !

I'm building a desktop database application, and i chose JavaDB as my database.

I've already done the connection to my database within the code, but i also want to inciate the JavaDB Server within the code.

How can i do that ?




http://platform.netbeans.org/tutorials/nbm-crud.html

Or maybe use a ModuleInstall class.

Gj
Quote:
Thanks !!

------------------------
Brazilian Computer Engineering Student !




Back to top
Geertjan Wielenga
Posted via mailing list.





PostPosted: Tue Mar 31, 2009 12:48 pm    Post subject: Iniciate JavaDB within the code Reply with quote

Geertjan Wielenga wrote:
Quote:
Unleash wrote:
Quote:
Hi !

I'm building a desktop database application, and i chose JavaDB as my
database.

I've already done the connection to my database within the code, but
i also want to inciate the JavaDB Server within the code.

How can i do that ?




http://platform.netbeans.org/tutorials/nbm-crud.html

Or maybe use a ModuleInstall class.

Gj
Oh, but probably you're not using the NetBeans Platform. Because this is
the nbj2ee mailing alias.

Gj
Back to top
Daoud AbdelMonem Faleh
Posted via mailing list.





PostPosted: Tue Mar 31, 2009 1:01 pm    Post subject: Iniciate JavaDB within the code Reply with quote

private static InetAddress localhost;
private static NetworkServerControl server;

static {
try {
localhost = InetAddress.getByName("127.0.0.1");
server = new NetworkServerControl(localhost, 1527);
} catch (UnknownHostException ex){
reportException(ex);
} catch (Exception ex) {
reportException(ex);
}
}

You *might* be interested in this section[1] of derby dev guide

[1] http://db.apache.org/derby/docs/10.0/manuals/develop/develop31.html

HTH,
Daoud AbdelMonem Faleh.


Unleash a
Back to top
jyeary



Joined: 21 Oct 2008
Posts: 606
Location: Simpsonville, SC

PostPosted: Wed Apr 01, 2009 1:35 am    Post subject: Iniciate JavaDB within the code Reply with quote

I believe I understand that you want to start the server from your code. There is an example of doing this in the demo directory of the JavaDB download. It shows you how to start a network server version, or how to start the embedded version.

Please check those sources for what you need.

On Tue, Mar 31, 2009 at 8:08 AM, Unleash <address-removed ([email]address-removed[/email])> wrote:
Quote:
Hi !

I'm building a desktop database application, and i chose JavaDB as my database.

I've already done the connection to my database within the code, but i also want to inciate the JavaDB Server within the code.

How can i do that ?



Thanks !!

------------------------
Brazilian Computer Engineering Student !







--
John Yeary
--
http://javaevangelist.blogspot.com

"Far better it is to dare might things, to win glorious triumphs, even though checkered by failure,

than to take rank with those poor spirits who neither enjoy much nor suffer much, because they live in the grey

twilight that knows not victory nor defeat." -- Theodore Roosevelt
Back to top
Rocco



Joined: 08 Jan 2009
Posts: 17
Location: Orta di Atella (CE, Italy)

PostPosted: Wed Apr 01, 2009 10:27 am    Post subject: Reply with quote

Try this:

NetworkServerControl s;
try {
s = new NetworkServerControl(); /* without parameters, means localhost:1527 */
s.start(null);
} catch (Exception ex) {
//catch exception here...
}


To shutdown, s.shutdown();
Back to top
Unleash



Joined: 19 Sep 2008
Posts: 12
Location: Brazil

PostPosted: Tue Apr 07, 2009 1:56 pm    Post subject: Reply with quote

Thank you all guys !

But i had another doubt ... about a jtable:

My app has some jtextfields, and their values are shown on jtable, each one at a column. But i vinculate the value of one jtextfield with another jtextfield (i make a calculation with the value of one and show the result in the other).
But the value shown in this jtextfield that contains the result is not shown at the correspondent column at the jtable.

How can i fix this ?
Back to top
Unleash



Joined: 19 Sep 2008
Posts: 12
Location: Brazil

PostPosted: Mon Apr 13, 2009 12:47 pm    Post subject: Reply with quote

Following your advices, i look in the demo directory of the JavaDB download and found what i wanted. But the IDE accuses a missing package:

org.apache.derby.drda.NetworkServerControl;

I have already added the derby.jar to the library of the project.
How can i fix it ?

thanks !


Edit: I added the derbynet.jar and fixed my problem. Now i'm working on connect to my database within the code. Sorry for being precipitate !
Back to top
Daoud AbdelMonem Faleh
Posted via mailing list.





PostPosted: Tue Apr 14, 2009 12:14 pm    Post subject: Iniciate JavaDB within the code Reply with quote

You need to have derbynet.jar into your classpath
Right click on your Libraries node into your project and choose "Add
Jar/Folder".

HTH,
Daoud AbdelMonem Faleh.

Unleash a
Back to top
Unleash



Joined: 19 Sep 2008
Posts: 12
Location: Brazil

PostPosted: Tue Apr 14, 2009 1:38 pm    Post subject: Reply with quote

Thanks !
But now i have another problem:
My database is already created and placed on the directory chosen on Java DB -> Properties -> Database Location.

How can i connect to this database within my code ?
I tried this, without success:

Connection con = null;
try{
Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
}catch (Exception ex){
System.out.println(ex.getMessage());
}

con = DriverManager.getConnection("jdbc:derby://localhost:1527/CRHDatabase","crh","crh");


Thanks !
Back to top
jyeary



Joined: 21 Oct 2008
Posts: 606
Location: Simpsonville, SC

PostPosted: Tue Apr 14, 2009 5:37 pm    Post subject: Iniciate JavaDB within the code Reply with quote

I have my system set up to create the database in a known location. For example use the System.getProperty("user.home") to set the path to my database. So my database would exist in the home directory.

John

On Tue, Apr 14, 2009 at 9:39 AM, Unleash <address-removed ([email]address-removed[/email])> wrote:
Quote:
Thanks !

But now my problem is another:

My database is already created and placed on the directory chosen on Java DB -> Properties -> Database Location.



How can i connect to this database within my code ?

I tried this, without success:



Connection con = null;

Back to top
jyeary



Joined: 21 Oct 2008
Posts: 606
Location: Simpsonville, SC

PostPosted: Tue Apr 14, 2009 5:38 pm    Post subject: Iniciate JavaDB within the code Reply with quote

I just noticed that you are using the embedded driver and not the network driver. You will need to change your connection syntax. Check the documentation.

On Tue, Apr 14, 2009 at 9:39 AM, Unleash <address-removed ([email]address-removed[/email])> wrote:
Quote:
Thanks !

But now my problem is another:

My database is already created and placed on the directory chosen on Java DB -> Properties -> Database Location.



How can i connect to this database within my code ?

I tried this, without success:



Connection con = null;

Back to top
Melongo Annabel
Posted via mailing list.





PostPosted: Tue Apr 14, 2009 11:21 pm    Post subject: Iniciate JavaDB within the code Reply with quote

Have you added the db driver to your project's classpath? If you do so, I think it will work.


From: John Yeary <address-removed>
To: address-removed
Sent: Tuesday, April 14, 2009 12:15:50 PM
Subject: Re: [nbj2ee] Iniciate JavaDB within the code

I just noticed that you are using the embedded driver and not the network driver. You will need to change your connection syntax. Check the documentation.

On Tue, Apr 14, 2009 at 9:39 AM, Unleash <address-removed ([email]address-removed[/email])> wrote:
Quote:
Thanks !

But now my problem is another:

My database is already created and placed on the directory chosen on Java DB -> Properties -> Database Location.



How can i connect to this database within my code ?

I tried this, without success:



Connection con = null;

try{

Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();

}catch (Exception ex){

System.out.println(ex.getMessage());

}



con = DriverManager.getConnection("jdbc:derby://localhost:1527/CRHDatabase","crh","crh");





Thanks !

------------------------
Brazilian Computer Engineering Student !







--
John Yeary
--
http://javaevangelist.blogspot.com

"Far better it is to dare might things, to win glorious triumphs, even though checkered by failure,

than to take rank with those poor spirits who neither enjoy much nor suffer much, because they live in the grey

twilight that knows not victory nor defeat." -- Theodore Roosevelt
Back to top
Unleash



Joined: 19 Sep 2008
Posts: 12
Location: Brazil

PostPosted: Wed Apr 15, 2009 1:14 pm    Post subject: Reply with quote

I've already checked all documentation i found. Just can't iniciate java db server and connect to my database within the code.

If i start the Java DB server within the code, my app can't find my database. My code to connect to my database works, but to make it work i have to start the server with right click on Java DB -> Start Server ....


I've already added the driver to the classpath(derby.jar) ... and i'm trying to use the network driver ...

The code i was trying:

//Start server

NetworkServerControl s;
try {
s= new NetworkServerControl();
s.start(null);
}catch (Exception ex){
System.out.println(ex.getMessage());
}

//Connect to the database
try{
Class.forName("org.apache.derby.jdbc.ClientDriver");
Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/CRHDatabase", "crh", "crh");
launch(CRHDatabaseApp.class, args);
}catch (Exception ex){
System.out.println("Error: " + ex.getMessage());
}



PLEASE HELP !!
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo