OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

is it possible to connect to a not register DB?

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
briglia23
OOo Enthusiast
OOo Enthusiast


Joined: 24 Jun 2008
Posts: 121

PostPosted: Wed Jun 17, 2009 3:14 am    Post subject: is it possible to connect to a not register DB? Reply with quote

is it possible to connect to a not register DB by macro?

Thanks
Back to top
View user's profile Send private message
pitonyak
Administrator
Administrator


Joined: 09 Mar 2004
Posts: 3655
Location: Columbus, Ohio, USA

PostPosted: Sat Jun 20, 2009 3:51 pm    Post subject: Reply with quote

Yes
_________________
--
Andrew Pitonyak
http://www.pitonyak.org/oo.php
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
pitonyak
Administrator
Administrator


Joined: 09 Mar 2004
Posts: 3655
Location: Columbus, Ohio, USA

PostPosted: Sat Jun 20, 2009 3:53 pm    Post subject: Reply with quote

See here:

http://www.pitonyak.org/database/AndrewBase.odt
_________________
--
Andrew Pitonyak
http://www.pitonyak.org/oo.php
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
briglia23
OOo Enthusiast
OOo Enthusiast


Joined: 24 Jun 2008
Posts: 121

PostPosted: Tue Jun 23, 2009 5:25 am    Post subject: Reply with quote

I read your document an i have a question.

To connect to Db i use this code

Code:

Dim oBaseContext  'Global database context.
Dim oDataSource   'Data source for the specified database.
Dim oCon          'Connection to a database.
Dim sUser$        'User name while connecting.
Dim sPassword$    'Password while connections.

REM Set the user name and password for connection.
REM There is no user or password required so set to an empty string.
sUser = ""
sPassword = ""

oBaseContext = CreateUnoService("com.sun.star.sdb.DatabaseContext")
oDataSource = oBaseContext.getByName("MyDB")
oCon = oDataSource.getConnection(sUser, sPassword)
oCon.close()


If my Db is a remote DB how can i do to select my DB?

P.S: I can't register a DB

Thank you
Back to top
View user's profile Send private message
briglia23
OOo Enthusiast
OOo Enthusiast


Joined: 24 Jun 2008
Posts: 121

PostPosted: Wed Jun 24, 2009 1:06 am    Post subject: Reply with quote

why this code doesn't works?

Code:


Sub Main

Dim oBaseContext  'Global database context.
Dim oDataSource   'Data source for the specified database.
Dim oCon          'Connection to a database.
Dim sUser$        'User name while connecting.
Dim sPassword$    'Password while connections.

REM Set the user name and password for connection.
REM There is no user or password required so set to an empty string.
sUser = ""
sPassword = ""

oBaseContext = CreateUnoService("com.sun.star.sdb.DatabaseContext")
odbURL = convertFromURL("C:\Utenti\yacme\Documenti\")
oDataSource = oBaseContext.getByName(odbURL & "testBDB.odb")
oCon = oDataSource.getConnection(sUser, sPassword)
oCon.close()

End Sub


this code
Code:
oDataSource = oBaseContext.getByName(odbURL & "testBDB.odb")

returns to me a NoSuchElement exception

Off course i have the testBDB.odb in C:\Utenti\yacme\Documenti\ but it is a not register DB.

Thank you
Back to top
View user's profile Send private message
Lew Wadoo
General User
General User


Joined: 05 Jul 2009
Posts: 7
Location: Russia, Moscow

PostPosted: Sun Jul 05, 2009 2:08 am    Post subject: "file:///" missing Reply with quote

briglia23 wrote:
why this code doesn't works?

Code:


Sub Main

Dim oBaseContext  'Global database context.
Dim oDataSource   'Data source for the specified database.
Dim oCon          'Connection to a database.
Dim sUser$        'User name while connecting.
Dim sPassword$    'Password while connections.

REM Set the user name and password for connection.
REM There is no user or password required so set to an empty string.
sUser = ""
sPassword = ""

oBaseContext = CreateUnoService("com.sun.star.sdb.DatabaseContext")
odbURL = convertFromURL("C:\Utenti\yacme\Documenti\")
oDataSource = oBaseContext.getByName(odbURL & "testBDB.odb")
oCon = oDataSource.getConnection(sUser, sPassword)
oCon.close()

End Sub


this code
Code:
oDataSource = oBaseContext.getByName(odbURL & "testBDB.odb")

returns to me a NoSuchElement exception

Off course i have the testBDB.odb in C:\Utenti\yacme\Documenti\ but it is a not register DB.

Thank you


Try to add this before the path: "file:///".
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
briglia23
OOo Enthusiast
OOo Enthusiast


Joined: 24 Jun 2008
Posts: 121

PostPosted: Mon Jul 06, 2009 8:03 am    Post subject: Reply with quote

Solved, the path wasn't ok

odbURL = convertFromURL("C:\Utenti\yacme\Documenti\") KO

odbURL = convertFromURL("C:\Users\yacme\Documents\") OK

Thank you.
Back to top
View user's profile Send private message
Amin405
Power User
Power User


Joined: 13 Nov 2009
Posts: 56

PostPosted: Mon Nov 23, 2009 2:02 am    Post subject: MYSQL Database Reply with quote

OK this is good, but what command I should use for existing MySQL database with username of "root" and address of "localhost"
_________________
Amin
Back to top
View user's profile Send private message Send e-mail
QuazzieEvil
Super User
Super User


Joined: 17 Jan 2007
Posts: 599
Location: Houston, TX

PostPosted: Mon Nov 23, 2009 7:46 am    Post subject: Reply with quote

First, you need to create an *.ODB file that connects to your db server at said host and port. Then proceed to access the ODB file with

Code:
oDataSource=oBaseContext.getByName(url)

_________________
Free Docs @ http://www.baseprogramming.com/resources.html
Book @ lulu.com http://www.lulu.com/content/2455551
Back to top
View user's profile Send private message Visit poster's website
Amin405
Power User
Power User


Joined: 13 Nov 2009
Posts: 56

PostPosted: Tue Nov 24, 2009 12:55 am    Post subject: MySQL Database Reply with quote

I have put the following code:


Sub Main

Dim oBaseContext 'Global database context.
Dim oDataSource 'Data source for the specified database.
Dim oCon 'Connection to a database.
Dim sUser$ 'User name while connecting.
Dim sPassword$ 'Password while connections.

REM Set the user name and password for connection.
REM There is no user or password required so set to an empty string.
sUser = "root"
sPassword = ""

oBaseContext = CreateUnoService("com.sun.star.sdb.DatabaseContext")
odbURL = convertFromURL("H:\Project\Spreadsheet\")
oDataSource = oBaseContext.getByName(odbURL & "test.odb")
oCon = oDataSource.getConnection(sUser, sPassword)
oCon.close()

End Sub


But when it reaches this line:

oDataSource = oBaseContext.getByName(odbURL & "test.odb")

it says:
BASIC runtime error.
An exception occurred
Type:com.sun.star.container.NoSuchElementException
Message: H\Project\Spreadsheet\test.odb


I have tried your code QuazzieEvil
with that I get same error, but I'm not sure I typed it correctly:
Sub Main

Dim oBaseContext 'Global database context.
Dim oDataSource 'Data source for the specified database.
Dim oCon 'Connection to a database.
Dim sUser$ 'User name while connecting.
Dim sPassword$ 'Password while connections.

sUser = "root"
sPassword = ""

oBaseContext = CreateUnoService("com.sun.star.sdb.DatabaseContext")
odbURL = convertFromURL("H:\Project\Spreadsheet\test.odb")
oDataSource=oBaseContext.getByName(url)
oCon = oDataSource.getConnection(sUser, sPassword)
oCon.close()

End Sub


Actually what I'm looking for is that I would like to connet each cell of spreadsheet to correspond value in MySQL database
_________________
Amin
Back to top
View user's profile Send private message Send e-mail
QuazzieEvil
Super User
Super User


Joined: 17 Jan 2007
Posts: 599
Location: Houston, TX

PostPosted: Tue Nov 24, 2009 5:27 am    Post subject: Reply with quote

Your problem may be that you are using convert FromURL(..) rather than convertToURL(...)
_________________
Free Docs @ http://www.baseprogramming.com/resources.html
Book @ lulu.com http://www.lulu.com/content/2455551
Back to top
View user's profile Send private message Visit poster's website
Amin405
Power User
Power User


Joined: 13 Nov 2009
Posts: 56

PostPosted: Tue Nov 24, 2009 5:29 am    Post subject: Reply with quote

Nope, I tried, still same problem.
_________________
Amin
Back to top
View user's profile Send private message Send e-mail
Amin405
Power User
Power User


Joined: 13 Nov 2009
Posts: 56

PostPosted: Thu Dec 03, 2009 2:42 am    Post subject: Reply with quote

Is there any code that have access to a certain value in the MySQL database?

e.g. database name="Test"; Table name="BOOK"; Field="ID"; Value="5632723"

How do we write such a sql code in calc macro to have access to desired database:

Code:
SELECT b.`ID`, FROM  BOOK b;
WHERE ID =5632723

_________________
Amin
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
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


Powered by phpBB © 2001, 2005 phpBB Group