Netbeans derby embedded error - tableview

I have created a GUI alp with a database. I have a problem with the Embedded connection.
I made this Embedded connection in Services tab > drivers > Java DB (Embedded) and connect using.
I enter the data as follows:
;create=true is what I write because it generally will not create a database folder in the app folder. I create a table and I put that URL in jer the code con = DriverManager.getConnection
When I start the app and when I enter the data in the respective fields that should fill in this database, the following error appears:
java.-sql.SQLSyntaxErrorException: Table/View 'nameTable' does not exists!
I first added derby.jar driver to the library and then I added Java DB driver which comes with Netbeans, but the error remains. The same error appears no matter what I do.
Here a code:
private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) {
try { Connection con;
Connection db = null;
con = DriverManager.getConnection("jdbc:derby:testBase;create=true ", "app", "admin77");
Statement stmt = con.createStatement();
String Query ="INSERT INTO LINGU (NAME , CONCTRACTNO , EMAIL , PHONE , VIBER ) VALUES ('"+fNameLname.getText()+"' , '"+contTxt.getText()+"' , '")
stmt.execute(Query);
JOptionPane.showMessageDialog(null,"You have successfully added this vendor to the list of Lingu vendors.");
fNameLname.setText(null);
contTxt.setText(null);
emailTxT.setText(null);
phoneTxT.setText(null);
viberBox.setSelectedIndex(0);
}
catch(SQLException ex){
JOptionPane.showMessageDialog(null, ex.toString());
}
}
Table:

With a JDBC Connection URL like jdbc:derby:testBase;create=true, you are telling Derby to access a database named testBase, which is to be found in a folder named testBase relative to whatever is the current working directory when you run your program.
And you are also telling Derby that, if there is no database in a folder named testBase relative to whatever is the current working directory when you run your program, Derby should go ahead and create a new fresh empty database in that location.
This approach makes it easy to confuse yourself, because if you run the program once in one directory, and create some tables and load some data, and then run the program again in a different directory, it will seem like all your tables have vanished and all your data is gone.
(It isn't, it's just that you've now created two different databases, and you're confused about which database you're using with which run of your program.)
Note that, from the point of view of Derby, the NetBeans IDE is just another program that is using Derby, and the NetBeans IDE, itself, has its own "current working directory", and it is almost certainly not the same as the current working directory that you use when you run your program by hand.
Derby's ability to use relative filesystem paths for database locations, and its ability to quietly manufacture a new empty database on demand (create=true) are very nice features, but they can also be very confusing when you are just starting to learn Derby.
A fairly simple alternative is to avoid using relative database path names in your JDBC Connection URL, and instead always use an absolute database pathname, like:
jdbc:derby:/path/to/my/db/folder/testBase
Then you will find that you are always using the same database, and your data will be there the next time you go open that database.

Related

Is Oracle Database Supported in Joomla?

I would like to use Oracle database instead of MySQL in Joomla. Is this possible with Joomla, is there a workaround or a solution on how to implement Oracle database with Joomla? Any information will be greatly appreciated.
It is said that it can be done, but it is not a job for beginners and took those guys 3 working days to do it.
Here's why that combination doesn't work by default:
The database and table creation script does not work without modification.
The connection and the database class are written to connect to MySQL and not to Oracle (so they all use MySQL functions).
Some of the extensions use native MySQL functions directly, instead of connecting using the Joomla Database interface (class).
This is what they did to make it work:
We fix the SQL installation script to accommodate the Oracle database in case of a new installation. In case of an existing installation, we export all the database, as well as its data to a SQL file, and then we modify the SQL file (using find and replace) to make it work with an Oracle database.
We load the modified installation file or the modified exported SQL file into the Oracle database.
We then create a copy of the Joomla database class, and then we modify all the functions to work with Oracle instead of MySQL.
We ensure that the Oracle drivers are properly installed and loaded by the php.ini file.
We rename the original MySQL database (you will know in the next step why) to something like database_name_old.
We switch to the new database class and fully test the website to see if some extensions are not working. If an extension ceases to work then it is a sign that this extensions is calling the original MySQL database (which no longer exists because it was renamed) directly.
Hopefully, you aren't a beginner and those guidelines will help you do it. Otherwise, check how much it might cost by visiting the page.

Can I Restore data from ORACLE datafiles folder?

my server had been attacked by a ransomware .rapid and all my data had been encrypted , luckily for me the oracle home folder is not encrypted - yet - and most of the files including the datafiles folder and tablespaces are still accessible
Can any One please tell me how to recover my database objects?
no backup is available , only oracle home folder -most of it-
EDIT :
The System is broken , I am trying to know witch files to collect and copy that will enable me to recover my database files from another system
when I try to log into sqlplus throw cmd I get the following error :
'sqlplus' is not recognized as an internal or external command ,
operable program or batch file.
Blockquote
EDIT :
FILES THAT I STILL HAVE ACCESS TO - NOT ENCRYPTED -
Okay. If you can find an init.ora file on your server, that's the PFILE - initialization parameter file - that's the last thing missing to easily copy your database to a new server. If you can't find it, that's ok - it'll just be a little harder. As long as you have the datafiles, you can eventually get your database back.
Basically, you'll want to follow steps 2-8 in the link I posted. You can also find some helpful info in the Oracle guide to manually creating a database in Windows. I'll walk you through them.
Shutdown your old database (if it's still running). This will make sure your datafiles are in a consistent state for copying. Probably stopping the Windows Service would be the easiest way to do that if you can't access sqlplus.
Copy the data to your new server. I'm assuming it'll be in the same location, D:\app\Administrator\oradata\VTC\
Make a copy of the control file CONTROL01.CTL and name it create_db.sql (EDIT: I was assuming that this was a backup to trace ascii version of the control file, but it sounds like this is the binary file)
Edit create_db.sql. Where it says CREATE CONTROLFILE REUSE DATABASE "MY_DB" NORESETLOGS, change it to CREATE CONTROLFILE SET DATABASE "MY_DB" RESETLOGS. Make note of whatever "MY_DB" is - this is your database name. Most people make it the same as the SID. I normally do RESETLOGS which throws out the old redo logs, but you could try keeping them with NORESETLOGS if that works for you.
Remove or comment out the lines that say RECOVER DATABASE and ALTER DATABASE OPEN;. Make sure the paths for the datafiles and logfiles look correct. Save the file.
If you couldn't find your init.ora to copy, I think this very minimal one will work for you, although you'll want to fix your memory settings later. Create it in the same folder.
DB_NAME=MY_DB
INSTANCE_NAME=MY_DB
SERVICE_NAMES=MY_DB
CONTROL_FILES = ("D:\app\Administrator\oradata\VTC\CONTROL01.CTL")
DB_FILES=100
Create an Oracle Database Windows Service. Afterwards check Services to make sure it's running.
oradim -NEW -SID MY_DB -STARTMODE manual -PFILE "D:\app\Administrator\oradata\VTC\init.ora"
Log in to your new Oracle instance as SYSDBA. There's no database yet.
cd D:\app\Administrator\oradata\VTC\
set ORACLE_SID=MY_DB
sqlplus / as sysdba
Create the database, using the control file from the old server as a script.
#create_db.sql
If everything comes back OK, run:
alter database open

setting up remote connection with an existing monetdb db

I create a monetdb database using mserver5 (in actual fact I use R and MonetDB.R for this part).
Retrospectively (once the db has been created) I would like to do the following:
set a remote connection to the db
set a passphrase for the remote connection (apparently necessary)
Please note that from the manuals I think I can do the above on a new dbFarm created with monetdbd.
My problem is to do the above retrospectively on an existing db.
To start I tried to use monetdbd and pointing it to the db folder (created by mserver5) with
monetdbd get all myFolderCreatedWithmserver5
But I get
unable to read properties from myFolderCreatedWithmserver5: no such file or directory
You are most probably providing monetdbd the wrong folder. You can identify the "dbfarm" folder by its contents:
.merovingian_lock
merovingian.log
.merovingian_properties
one folder for each database
If you provide a folder above this one, or any folder of a database, you will get the above error message.

Exception caused while querying Hive Derby database via JDBC

I am a new user to Hive and have just started using it for a project. I am having problem connecting to the database using java. It is explained as follows:
I ran Hive database on my machine that created a derby metastore_db using the Embedded Derby Driver. Now, I wish to query this metastore_db via a separate Java program for issuing queries.
I followed multiple tricks that I could find online but still am not able to get that working.
Snapshot of my Java file:
String url = "jdbc:derby:metastore_db;create=true";
String username = "APP";
String password = "mine";
String drivername = "org.apache.derby.jdbc.EmbeddedDriver";
Connection con = DriverManager.getConnection(url,username, password);
Statement stmt = con.createStatement();
res = stmt.executeQuery("describe " + tableName);
Running the java file:
I have placed it in the same folder as the metastore_db and then running it using the following command:
java -cp "derby-10.4.2.jar:." ConnectTesting
I get the following syntax exception:
java.sql.SQLException: Syntax error: Encountered "describe" at line 1, column 1.
Some of the things I have already tried:
url = "jdbc:derby:metastore_db;create=false";
url = "jdbc:derby://localhost:10000/metastore_db";
url = "jdbc:derby://localhost:1527/metastore_dbDB"; // By default port at which hive listens
The above two give error as:
No suitable driver found for jdbc:derby://localhost:10000/metastore_db
url = "jdbc:derby:<full_path_to_db>/metastore_db";
If I have my HIVE server already running, and then from another terminal I execute the java file, it says:
"Another instance of Derby may have already booted the database "
Can anyone kindly point out as to what am I doing wrong and how can I connect to the already existing database to issue queries.
That's a lot of different questions. Which one do you really need answered?
"describe" is a command implemented by the "ij" tool; it is not a SQL statement. So to run "describe", you have to run it from "ij" (or by using the RunScript utility to run "ij" within your application; you cannot run it directly from Statement.executeQuery().
In order to use the client-server driver, with the hostname:port syntax, you have to (a) use the derbyclient.jar rather than the derby.jar in your classpath, and (b) have the Network Server running.
And, you cannot have the same Derby (embedded) database open in multiple applications simultaneously, so while your application is running, you cannot run a second application against the same (embedded) database. If you need this functionality, you need to switch all your applications to using the client driver, and run the Network Server to provide multi-application access to your database.
Have you run the Derby tutorial yet? It covers most of these topics in more detail: http://db.apache.org/derby/docs/10.10/getstart/

ActiveRecord with Derby How to Set Derby Schema

See "UPDATE" below for what I now know is the crux of the problem.
I have a legacy Derby database that I want to make a Rails application to interface with.
I am using RVM so here are the steps I took:
1. rvm install jruby (installed 1.6.7.2)
2. rvm use jruby
3. gem install rails
4. rails new myapp
5. add "gem 'activerecord-jdbcderby-adapter'" to Gemfile of new rails app
6. bundle
7. copied my derby db folder (named 'perm') under db in the rails app
8. changed database.yml as follows:
development:
adapter: jdbcderby
database: db/perm
Then I made a model file and used set_table_name to set it to one of the table names and when I run rails c I get an exception that the table does not exist.
Also in the console when I do
ActiveRecord::Base.connection.tables
the only table that comes back is "schema_migrations".
I know there is nothing wrong with the database as I can connect to this exact copy and see all the tables using SquirrelSQL. Also, the rails app is connecting in some way since when I open the console I cannot, while the console is running, connect to the same instance using SquirrelSQL, and vice versa.
Does anyone have any suggestion as to why active record doesn't see the tables?
UPDATE:
The problem has something to do with how derby "organizes" tables into multiple "schemas" in the same file. When I create a new table from rails (i.e. with a migration) the table ends up in the "SA" schema. All of my legacy tables are in the "APP" schema (maybe I could move them but I don't want to do that if I can avoid it...other apps would break). So when I access the db from rails this way it's like only the "SA" schema exists. How do I tell Rails to 'use' the "App" schema (early on I tried prefacing the table name but that didn't work)?
I retitled the question accordingly.
UPDATE #2:
Apparently the jdbcderby gem supports the "schema" setting. On a guess I tried changing my database.yml to the following:
development:
adapter: jdbcderby
database: db/perm
schema: app (also tried APP)
When I have the app (or APP) schema setting when I do ActiveRecord::Base.connection.tables in the console I get the list of tables from the app schema (the list shows up with table names all lower case with no schema name).
But I am still having trouble accessing the tables. When I make a model file on an existing table and try to access it I get a JDBCError: "Schema 'SA' does not exist". I have tried various set_table_name calls with no success.
As far as I know there is nothing unusual about my database. But there is no information anywhere on how to do this. Am I the only person on earth who has ever tried to use a legacy Derby database with Rails?
The database name 'db/perm' is being interpreted relative to your current working directory, which is probably not the directory that you think it is. Try either (1) searching your hard disk for the file 'derby.log', which is probably being created in the actual current working directory of your rails app, or (2) specifying the absolute file path to your derby database, not a relative file path.
If the problem is the schema, Derby supports the SET SCHEMA statement: http://db.apache.org/derby/docs/10.8/ref/rrefsqlj32268.html
If you don't explicitly set the schema, it defaults to the username that you connect with, so you can also indirectly set the schema by logging in as the desired username.

Resources