jaydebeapi | JayDeBeApi module allows you to connect from Python code | Database library
kandi X-RAY | jaydebeapi Summary
kandi X-RAY | jaydebeapi Summary
JayDeBeApi module allows you to connect from Python code to databases using Java JDBC. It provides a Python DB-API v2.0 to that database.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Connect to jdbc
- Return a fully qualified classpath
- Glob for jars
- Connect to Jupyter
- Set the java classpath
- The column description
- Map a JDBC type to the default type code
- Convert Java Dataset to Python BigDecimal
- Convert Java method to python
- Prepare the jdb connection
- Convert a function into a string
jaydebeapi Key Features
jaydebeapi Examples and Code Snippets
Community Discussions
Trending Discussions on jaydebeapi
QUESTION
I am connecting to a db using jaydebeapi and a jdbc driver using the following snippet, that works fine when the all parameters are correctly specified.
I am storing my credentials in environment variables e.g. os.environ.get('credentials')
ANSWER
Answered 2021-Dec-13 at 14:14You are using the default traceback logger of pytest, which also logs the arguments passed to a specific function. One way to solve this kind of leak is to use another traceback mode. You can find the general documentation at this link. In that link you can find two interesting traceback modes:
--tb=short
--tb=native
Both give you all the information you need during your specific test since:
- They still give you information about the tests failed or succeded
- Since you are using parametrized tests, the logs about failures will look like
FAILED test_issue.py::test_connectivity[server_name-server_jdbc_port-server_database-name_env_credentials-name_env_pwd]
, in this way you can identify the actual failing test
Mind that this solution, while avoiding to log the credentials used at test time, these credentials used during testing must not be the same that will be used outside the test environment. If you are concerned with the fact that in case of failures in production, the logger could leak your credentials, you should setup you logger accordingly and avoid to log the default text of the exception.
QUESTION
So I am having some performance issues with my program. When I run it, it crashes nearly every time. Most likely, the program cannot process over a million rows at once. This occurs when I run cursor.fetchall()
in the code below:
ANSWER
Answered 2021-May-18 at 22:52Per our discussion, slightly modifying the code to use cursor.fetchone()
over cursor.fetchall()
will prevent your program from crashing but it will be slow as mentioned due to deserialization through the JVM.
QUESTION
I'm connecting to a Oracle database using the following code:
...ANSWER
Answered 2021-Apr-06 at 09:14This seems to be a problem when using jaydebeapi
with jpype
. I can reproduce this when connecting to a Oracle db in the same way that you do (in my case Oracle 11gR2, but since you are using ojdbc8.jar
, I guess it also happens with other versions).
There are different ways you can solve this:
Change your connectionSince the error only seems to occur in a specific combination of packages, the most sensible thing to do is to try and avoid these and thus the error altogether.
Alternative 1: Use
jaydebeapi
withoutjpype
:As noted, I only observe this when using
jaydebeapi
withjpype
. However, in my case,jpype
is not needed at all. I have the.jar
file locally and my connection works fine without it:
QUESTION
Using the Keyword Query
from the Robot Framework DatabaseLibrary JayDeBeApi in conjunction with DB2 like this: ${results}= Query CREATE TABLE SCHEMANAME.TEST_TEMP (id BIGINT, name VARCHAR(25))
is being executed (table exists afterwards).
But nevertheless RobotFramework throws a FAIL and ${results} contains the Message DatabaseError: com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-601, SQLSTATE=42710, SQLERRMC=SCHEMANAME.TEST_TEMP;TABLE, DRIVER=4.14.122
and often even a very simple Message Error
after running the same statement.
Running the query above (copy/paste) directly within a database SQL window doesn't return any errors.
How is it possible, in RobotFramework the query is executed successfully but nevertheless an error is thrown?
...ANSWER
Answered 2021-Feb-03 at 18:40The error SQLCODE=-601 means that you are trying to create an object that already exists. So when you say that the table exists afterwards, it means that it existed before you ran the statement. I don't know the framework you are using, but the explanation by @pavelsaman in comment seems to be a very likely cause.
QUESTION
Task I am writing a Python script that makes some changes in a HSQL-DB and then rexecutes a java-programm via the command line, which works with the data in the DB. I am using jaydebeapi for altering the data in Python.
Problem The java program fails because it cannot obtain a DB lock. This is despite me having closed the cursor and connection as stated in the documentation.
...ANSWER
Answered 2021-Jan-14 at 00:42Your observations indicates that after the first connection via Python is closed, the database is still open.
The database is a resource that stays open once the first connection is made and it does not close automatically (by default). The .lck file prevents any other process from accessing the database.
You simply execute the SQL statement, SHUTDOWN
at the end of the first set of changes. This closes the database in a clean manner.
QUESTION
I am trying to connect and test a H2
database stored inside a local file with path:
/home/me/mydb.db
with RobotFramework
, where user is sa
without password.
I would like to know the proper string for connection.
I've tried to use jaydebeapi
with a downloaded h2 driver
.jar file but without success. Thank you for the help!
ANSWER
Answered 2021-Jan-05 at 16:43Well, I found the answer:
Connect To Database Using Custom Params jaydebeapi 'org.h2.Driver', 'jdbc:h2:/home/me/deployments/mydb.db', ['sa', ''], '/Developments/h2-1.4.197.jar'
QUESTION
I am using jpype, jaydebeapi to connect to an Oracle database which works fine but the sql returns tuples instead of strings with brackets and a comma after each character.
e.g. instead of dog it returns (d,o,g,)
Running the same sql in DBeaver or Toad returns the string without alteration as you would expect.
Any idea on how to return the string without brackets and comma please? (I can still use the data but it looks weird in a chart and makes the chart and other outputs harder to read).
I have already searched Google and stackoverflow for similar issues (link1,link2,link3) but non of these solutions have worked for me. I need to find a way to loop through all columns to find those with dtype string and then join all tuples in those.
Here is a screenshot of how the data is being returned: df_screenshot
Here is a screenshot of a pivot (showing the data can be used without using brackets and commas): pivot_screenshot
Here is a screenshot of a chart (again showing string with brackets and commas): chart_screenshot
The code I'm using for the connection is as follows (no issues with this as far as I can see?):
...ANSWER
Answered 2020-Dec-09 at 11:11I see two problems / ways to adress this:
The first way is to solve the "symptoms", i.e. work with the weird output you get and transform it to represent what it should be. This can be done using str.replace and str.join/str.split:
''.join(','.split("('d','o','g')".replace('(','').replace (')','')))
The second and better way, however, is to solve the underlying problem. I do not know where the problem is, but try executing your code line by line with a debugger to see where this malformed strings appear first.
QUESTION
I'm fetching data from a db with the use of jaydebeapi
pkg. I want to serialize the data (it's in list of tuples format) using pickle
.
The data may contain different java class types. For a certain data type () I get the following error message:
ANSWER
Answered 2020-Oct-28 at 07:31You should use the JPype Pickle Module instead of pickle.
QUESTION
I am trying to connect to Apache Drill from python using jaydebeapi
library.
I have turned on drill in embedded mode via drill-embedded
, and the web ui runs correctly in port 8047. Then, I am trying to connect via JDBC through a python script:
ANSWER
Answered 2020-Oct-07 at 08:43Thanks to @Luke Woodward suggestion, the problem was the port. For drill-embedded
there is no port to select. Below a full query example
QUESTION
I am currently looking for optimal way how to obtain a random data sample from the table (for instance in HIVE). I know that PRESTO provides either RANDOM() function or TABLESAMPLE BERNOULLI/SYSTEM. Problem is when querying table with significant number of records, it takes a lot of time, which is not suitable with cooperation with JayDeBeApi which might close the connection waiting too long for the response.
I would prefer to use TABLESAMPLE BERNOULLI/SYSTEM which takes as an argument percentage of the records to be fetched. To compare with ORACLE, SAP or MSSQL databases which enable to pass the precise percentage, i.e. 0.003123412%, the PRESTO does not allows you, despite that the function are quite similar, and everything is converted in the range 1-100%.
Does anyone know some workaround how to solve this? I would prefer to avoid the limit clause in cooperation with TABLESAMPLE BERNOULLI/SYSTEM which might not work as expected.
...ANSWER
Answered 2020-Sep-03 at 15:36This can be obtained by passing numbers in scientific notation.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install jaydebeapi
You can use jaydebeapi like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page