| View previous topic :: View next topic |
| Author |
Message |
briglia23 OOo Enthusiast

Joined: 24 Jun 2008 Posts: 121
|
Posted: Wed Jun 17, 2009 3:14 am Post subject: is it possible to connect to a not register DB? |
|
|
is it possible to connect to a not register DB by macro?
Thanks |
|
| Back to top |
|
 |
pitonyak Administrator


Joined: 09 Mar 2004 Posts: 3618 Location: Columbus, Ohio, USA
|
|
| Back to top |
|
 |
pitonyak Administrator


Joined: 09 Mar 2004 Posts: 3618 Location: Columbus, Ohio, USA
|
|
| Back to top |
|
 |
briglia23 OOo Enthusiast

Joined: 24 Jun 2008 Posts: 121
|
Posted: Tue Jun 23, 2009 5:25 am Post subject: |
|
|
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 |
|
 |
briglia23 OOo Enthusiast

Joined: 24 Jun 2008 Posts: 121
|
Posted: Wed Jun 24, 2009 1:06 am Post subject: |
|
|
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 |
|
 |
Lew Wadoo General User

Joined: 05 Jul 2009 Posts: 7 Location: Russia, Moscow
|
Posted: Sun Jul 05, 2009 2:08 am Post subject: "file:///" missing |
|
|
| 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 |
|
 |
briglia23 OOo Enthusiast

Joined: 24 Jun 2008 Posts: 121
|
Posted: Mon Jul 06, 2009 8:03 am Post subject: |
|
|
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 |
|
 |
Amin405 Power User


Joined: 13 Nov 2009 Posts: 56
|
Posted: Mon Nov 23, 2009 2:02 am Post subject: MYSQL Database |
|
|
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 |
|
 |
QuazzieEvil Super User

Joined: 17 Jan 2007 Posts: 599 Location: Houston, TX
|
|
| Back to top |
|
 |
Amin405 Power User


Joined: 13 Nov 2009 Posts: 56
|
Posted: Tue Nov 24, 2009 12:55 am Post subject: MySQL Database |
|
|
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 |
|
 |
QuazzieEvil Super User

Joined: 17 Jan 2007 Posts: 599 Location: Houston, TX
|
|
| Back to top |
|
 |
Amin405 Power User


Joined: 13 Nov 2009 Posts: 56
|
Posted: Tue Nov 24, 2009 5:29 am Post subject: |
|
|
Nope, I tried, still same problem. _________________ Amin |
|
| Back to top |
|
 |
Amin405 Power User


Joined: 13 Nov 2009 Posts: 56
|
Posted: Thu Dec 03, 2009 2:42 am Post subject: |
|
|
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 |
|
 |
|