Netbeans Database Explorer and Microsoft SQL Server not getting along - java

I am trying to get a Java desktop application to pull some data from a Microsoft SQL-Server 2008 Database. Netbeans database explorer can generate Entity classes from database tables, but I was unable to get this feature working. Normally, when you conect to a database, you see something like this:
I entered the database URL, username and password, and the connection was established. But when I tried to explore the tables, they were all empty. Instead of the nice tree above, I was just given a list of empty Schemas. Mutlitple user names were tried, all had the same issue. Since there was no schema on the database matching the username, a number of different schemas were displayed for me to choose. Regardless of which one I chose, when I expanded it nothing showed up inside the Table, or the Views.
To verify that the useranema and password did have access to the tables I am interested in, I wrote a short Java method to connect to the database and display the ResultSet for a query. It worked as expected. Why was the netbeans database explorer unable to find the tables?
I was hoping to use this tool to generate Entity classes with Netbeans, but apparently Microsoft SQL erver won't have it. I am using netbeans 7.1; documentation for the database explorer tool is found on db.netbeans.org

Yesterday I had the same problem with JDBC driver from Microsoft. I tried another one, the project jTDS (available on SourceForge). It could solve my problem. Some forums recommend always to use this driver because it is much faster.

Related

How do I share a Java Project with a JDBC and a SQL connection?

I made a french conjugator GUI using Java. I also created a SQL Database which had all the french verbs that users could pick and choose using SQL Workbench and connected it to the project.
When I tried to share it with my friends, they were able to access the Java project and see the various GUI elements, but none of the conjugations came up.
This is a screenshot that my friends sent me:
However, when I tried the same inputs I got a valid answer as seen here:
What can I do to fix this problem?
Thank you

I can't see or edit MySQL stored procedures in NetBeans

I can connect to MySQL database (5.7.23) from NetBeans (8.2) using JDBC (MySQL-AB JDBC Driver, mysql-connector-java-5.1.23). I can see tables and views, execute SQL statements and everything else with database but I cannot see or edit stored procedures (or functions) in NetBeans. I have them inside database, I can see and manage them in MySQL Workbench but cannot see them in NetBeans (folder "Procedures" in NetBeans is empty). What could be the problem?
Left in NetBeans, right in Workbench:
I have 64-bit Windows 10 Pro (1709), 64-bit NetBeans 8.2 (PHP) and 64-bit MySQL 5.7.14 (from WAMP).
There are possibly two reasons:
1. User doesn't have access to mysql.proc
NetBeans uses something like that to get the list of procedures and functions (see the source code):
SELECT
db, name, type, param_list, returns, body
FROM
mysql.proc
WHERE
TYPE = 'PROCEDURE' OR TYPE = 'FUNCTION';
Try to execute the query in NetBeans and see the result.
See the screenshot. On the first one, the user root has access to the mysql schema and you can see all system schemas including the mysql. On the second one, the user has access only to the information_schema and performance_schema and can not see procedures and functions:
Try to add to your user access to the MySQL schema. In workbench go to Server -> Users and Privileges -> Schema Privileges:
2. There is no mysql.proc in 8.0 mysql
Again, NetBeans uses mysql.pros extensively to get metadata about procedures and funcstions (see in source code). I suppose a simple workaround we can get is to create a view that would mimic the behavior of original mysql.proc:
CREATE VIEW mysql.proc AS
SELECT
ROUTINE_SCHEMA AS db,
ROUTINE_NAME AS name,
ROUTINE_TYPE AS type,
ROUTINE_DEFINITION AS body,
CONCAT(DTD_IDENTIFIER,
' CHARSET ',
CHARACTER_SET_NAME) AS returns,
(SELECT
GROUP_CONCAT(CONCAT(parameter_name, ' ', dtd_identifier))
FROM
information_schema.parameters p
WHERE
p.specific_name = outertable.routine_name
AND ordinal_position > 0) AS param_list
FROM
information_schema.routines outertable
After creating a view we can view procedures and functions from NetBeans 11.2 and view their bodies and param list. Also, I would not recommend editing procedures using NetBeans because it can't get full metadata. For example, it could not get declaration options such as DETERMINISTIC SQL SECURITY INVOKER.
I'm using netbeans 8.2 patch 2 and can show store procedure
And This is info netbeans which I'm using
I think you should be re-install full version netbeans.
This is quite annoying that I still haven't found the solution for this problem. This question is more than one year old. NetBeans changed from 8.2, 9, 10, now I use 11.2 and still this functionality does not work! I changed MySQL versions, NetBeans versions, JDBC driver versions!!! I must be related to regional settings of my machine that disrupts NetBeans!
On screenshot one can see that SHOW PROCEDURE STATUS in NetBeans shows the list of my stored procedures inside database but NetBeans does not show them in navigation tree!
It's really awkward that nobody else encountered this NetBeans strange behaviour.
The proof that it is the solution.
GRANT ALL PRIVILEGES ON mysql.proc TO '<user_name>'#'<host_name>';

Accessing Connected Database DB in Eclipse with Java Code

I successfully connected to a DB in eclipse through the Database Development perspective and am able to run queries in the SQL File Editor. However, I would like to write java code to automatically run a query and then extract the data to a flat file. What is the easiest way to do this? Since I am already connected to the database, can I bypass the java code that involves connecting to the database.
No, the Java JVM also needs to be able to connect to the database. There are many examples of JDBC connections on the internet, including this one.
Once you have got the data you needed, you should make use of FileWriter in order to write the information to file.

HSQLDB - hiding database structure/contents from users

I'm considering using HSQLDB version 1.8.x in a desktop app for storing local data. From what I can see, the database is stored on disk as a number of SQL statements to create the tables, insert the data, etc.
Is there a simple way I can hide this from users? I'm don't necessarily need it to be completely encrypted, etc - I'd just like to prevent the casual user from simply opening the file and seeing the structure of the database.
You could embed your database files within a jar file and connect to them using the notation:
jdbc:hsqldb:res:<path in jar>
Check out the Advanced Topics section of the HSQLDB guide for more information on this. However, I've never tried it so am not 100% sure it will work ...
The solution I've gone with for now is to call:
db.update("SET SCRIPTFORMAT COMPRESSED;");
to store the .script file in a human-unreadable form and:
db.update("SET PASSWORD password;");
to prevent more savvy users from opening the DB using their own HSQLDB client.
Unfortunately I was not able to execute below command
db.update("SET scriptformat COMPRESSED");
And was getting this error
java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: SCRIPTFORMAT
This error solved with this command
db.update("SET FILES SCRIPT FORMAT COMPRESSED");
I am using HSQLDB 2.3.3

Read Firefox 3 bookmarks

Firefox 3 stores the bookmarks in a sqlite database.
There are several hacked sqlite java libraries available.
Is there a way to hack the sqlite database in java(not using libraries) to read bookmarks reliably?
Does someone know how the sqlite DB is stored and access programmatically (from java)?
You need the SQLite JDBC driver (this page explains how to run queries on a SQLite database using that driver from within Java).
I don't know why you need NOT to use a JDBC driver, but there's another possible "solution" depending on your software requirements. In FF3, type in the address bar about:config
Alter the value of property: browser.bookmarks.autoExportHTML to true.
This will export your bookmarks in an HTML whenever you close FF. You can then read the HTML. It may or may not solve your problem....

Categories

Resources