Is it possible to connect to mysql database from writer without using base?

my purpose here is just to get a row of information from the database, no editing, no updating, no adding, no stored procedures, no queries, no sub tables… just get a single row of data and put it on writer, which the writer is also protected from being edited.
simply put, i just used writer to read a row of data so it can be printed or converted to PDF.

The question explicitly mentions “no base”, and is tagged “macro”. Yet, I figured I put this as an answer here.

The dedicated feature for exactly this task - pulling a row from a database, using it to populate fields in a Writer documents, and generate a resulting document from that merge (be in another Writer document, or a PDF, or an email message) - is called Mail Merge.

Its use does not require you to use Base directly (unless you want to fine-tune something). If you use Mail Merge wizard on an already saved writer document, it even does not create a separate ODB. But in any form, it does require Base component installed, since its functionality is used behind the scene.

Hello,

Yes, but as @mikekaganski noted, Base must be installed but a Base file is not created.

The answer come from The Pitonyak Guide Andrew Base. See section 8.6. Connections without a data source. Have used this method in this post: Connect to mssql (ODBC) database via Macro and just re-tested with macro from Calc to MySQL server 8.0.29 on Ubuntu 20.04 with LO 7.3.4.2:

Sub Main
Dim oParms() As New com.sun.star.beans.PropertyValue
AppendProperty(oParms(), "user", "YOUR_USER")
AppendProperty(oParms(), "password", "YOUR_PASSWORD")
sURL = "sdbc:odbc:YOUR_ODBC_CONNECTION"
oManager = CreateUnoService("com.sun.star.sdbc.DriverManager")
oCon = oManager.getConnectionWithInfo(sURL, oParms())
oStatement = oCon.CreateStatement()
sSQL = "SELECT * FROM " & DBQuoteName("YOUR_TABLE", oCon)
oResult = oStatement.executeQuery(sSQL)
Do While oResult.next()
s = s & oResult.getString(1) & " " & oResult.getString(2) & CHR$(10)
Loop
Print s
End Sub

Andrew Base guide also shows connection using JDBC.

1 Like