accidentally deleted h2 settings. How to retrieve them? - java

I am not able to find Sqlite and some other settings on the console. I accidentally removed it.
How can I restore or add new settings?

If you need to restore the default settings, search for the file .h2.server.properties in the home directory of your user and either delete this file or replace its content with the following default (from the current version) and edit it as necessary:
0=Generic JNDI Data Source|javax.naming.InitialContext|java\:comp/env/jdbc/Test|sa
1=Generic Teradata|com.teradata.jdbc.TeraDriver|jdbc\:teradata\://whomooz/|
10=Generic DB2|com.ibm.db2.jcc.DB2Driver|jdbc\:db2\://localhost/test|
11=Generic Oracle|oracle.jdbc.driver.OracleDriver|jdbc\:oracle\:thin\:#localhost\:1521\:XE|sa
12=Generic MS SQL Server 2000|com.microsoft.jdbc.sqlserver.SQLServerDriver|jdbc\:microsoft\:sqlserver\://localhost\:1433;DatabaseName\=sqlexpress|sa
13=Generic MS SQL Server 2005|com.microsoft.sqlserver.jdbc.SQLServerDriver|jdbc\:sqlserver\://localhost;DatabaseName\=test|sa
14=Generic PostgreSQL|org.postgresql.Driver|jdbc\:postgresql\:test|
15=Generic MySQL|com.mysql.cj.jdbc.Driver|jdbc\:mysql\://localhost\:3306/test|
16=Generic MariaDB|org.mariadb.jdbc.Driver|jdbc\:mariadb\://localhost\:3306/test|
17=Generic HSQLDB|org.hsqldb.jdbcDriver|jdbc\:hsqldb\:test;hsqldb.default_table_type\=cached|sa
18=Generic Derby (Server)|org.apache.derby.client.ClientAutoloadedDriver|jdbc\:derby\://localhost\:1527/test;create\=true|sa
19=Generic Derby (Embedded)|org.apache.derby.iapi.jdbc.AutoloadedDriver|jdbc\:derby\:test;create\=true|sa
2=Generic Snowflake|com.snowflake.client.jdbc.SnowflakeDriver|jdbc\:snowflake\://accountName.snowflakecomputing.com|
20=Generic H2 (Server)|org.h2.Driver|jdbc\:h2\:tcp\://localhost/~/test|sa
21=Generic H2 (Embedded)|org.h2.Driver|jdbc\:h2\:~/test|sa
3=Generic Redshift|com.amazon.redshift.jdbc42.Driver|jdbc\:redshift\://endpoint\:5439/database|
4=Generic Impala|org.cloudera.impala.jdbc41.Driver|jdbc\:impala\://clustername\:21050/default|
5=Generic Hive 2|org.apache.hive.jdbc.HiveDriver|jdbc\:hive2\://clustername\:10000/default|
6=Generic Hive|org.apache.hadoop.hive.jdbc.HiveDriver|jdbc\:hive\://clustername\:10000/default|
7=Generic Azure SQL|com.microsoft.sqlserver.jdbc.SQLServerDriver|jdbc\:sqlserver\://name.database.windows.net\:1433|
8=Generic Firebird Server|org.firebirdsql.jdbc.FBDriver|jdbc\:firebirdsql\:localhost\:c\:/temp/firebird/test|sysdba
9=Generic SQLite|org.sqlite.JDBC|jdbc\:sqlite\:test|sa
webAllowOthers=false
webPort=8082
webSSL=false
You need to restart the H2 Console after it.
If you already have some own settings in this file, don't forget to copy them.
You can also add new settings from the Login form, it has a Save button for that purpose, just fill the form and use this button.

Related

Table doesn't exists in Liferay 6

I have defined a data table and associated objects in Liferay 6, but when I run the code it says the table doesn't exists, and it's true. The code runs fine when I create the table by hand just copy-pasting the create table from the model implementation, but I expected the table to be created when deploying.
The user has all the privileges needed to create it.
What I'm missing?
I face the same problem. and #urvish is correct you have to change build number in
service properties file.
problem
When multiple developers working on portlet that uses servicebuilder
will give below exception “Build namespace has build number which is
newer than “. When developer commits service.properties file and that
deployed on other developer machine then it will throw below
exception
Best Practice: To avoid these kind of errors, follow these:
create service-ext.properties file at the same locaiton of service.properties
add build.number={higher-value or same value in exception)
Deploy portlet again
.
Check values of build.namespace in service.properties file and value of
select buildNumber from servicecomponent where buildNamespace = <<build.namespace from service.properties>>
Now the buildNumber return from query must be lesser than value of build.number propert in service.properties. If it is not then just set the value of build.number to 9999.
Sometimes due to mismatch, changes are not applied to database.

Why is Pentaho Report Designer adding parameter named "ce" to Database Connection of the report?

I am forced to use Pentaho Report Designer 5.4 and have following problem: Every time i try to make changes to Database Connection of the report, inside Options section designer adds parameter "ce" without any value - even if i previously deleted it (please see images below). When i open .prpt file and look inside sql-ds.xml, connection url looks as follows: "jdbc:sqlserver://192.168.1.194:1433;databaseName=statdb;integratedSecurity=false;ce"
problem is that my report was not loading at all. I looked into report log and found following lines:
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The connection string contains a badly formed name or value.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:190) ~[sqljdbc4.jar!/:na]
at com.microsoft.sqlserver.jdbc.Util.parseUrl(Util.java:445) ~[sqljdbc4.jar!/:na]
at com.microsoft.sqlserver.jdbc.SQLServerDriver.parseAndMergeProperties(SQLServerDriver.java:1026) ~[sqljdbc4.jar!/:na]
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1008) ~[sqljdbc4.jar!/:na]
I assume that appending parameter "ce" is causing the problem.
I have 2 questions:
Why is Pentaho Report Designer adding parameter named "ce" to Database Connection of the report?
Is Connection url in right format? Is parameter "ce" appended correctly?
This is 'instance name' defined such fashion. In your case option is blank since as I see on UI Instance name is also blank.
This is a bug most probably - 'ce' automatically added when connection edited. If you don't want database editor attempts to tweak you connection string such fashion - use 'Generic database' connection. You will have to specify full java class name and connection jdbc connection string. Also you have to have this jdbc driver on classpath and it can workaround most of such 'edit connection' issues.
Full guide can be found jdbc sqlserver dirver class
Run this query and get your instance name, and assign that value to the ce property in the Options tab and there you go :)
SELECT HOST_NAME() AS HostName, SUSER_NAME() LoggedInUser,SERVERPROPERTY('MachineName') AS [ServerName],
SERVERPROPERTY('ServerName') AS [ServerInstanceName],
SERVERPROPERTY('InstanceName') AS [Instance],
SERVERPROPERTY('Edition') AS [Edition],
SERVERPROPERTY('ProductVersion') AS [ProductVersion],
Left(##Version, Charindex('-', ##version) - 2) As VersionName

Is it possible to change HSQLDB mode to read-only on the fly?

I am using HSQLBD in file: mode.
(My usage of the HSQLDB is shown in my other question)
I need to receive a multiple-access to the database.script file.
By default, database is running with option readonly=false Here is some information from the official docs:
Readonly Databases
A file: catalog can be made readonly permanently, or it can be opened
as readonly. To make the database readonly, the property, value pair,
readonly=true can be added to the .properties file of the database.
The SHUTDOWN command must be used to close the database before making
this change.
It is also possible to open a normal database as readonly. For this,
the property can be included in the URL of the first connection to the
database.
With readonly databases, it is still possible to insert and delete
rows in TEMP tables.
But I am still not truly understood, is it possible to change this option on the fly, without server shutdown and without restart? If it is possible - can you please give some small code example?
And if not, is there some way to unlock the .script file and get the access for the different threads without the server shutdown?
Your requirement required to access HSQL internal class. The sample code is written for v2.3.3, it may not work for other version.
//import org.hsqldb.*;
//start server
Server.main(new String[]{"-database.0","file:s:/folder/dbname","-dbname.0","dbname","-no_system_exit","true"});
//set DB readonly
Database db = DatabaseManager.lookupDatabaseObject("file:", "s:/folder/dbname");
db.setReadOnly();
//alter connection to readonly
Session[] oa = db.sessionManager.getAllSessions();
for (int i = 0; i < oa.length; i++) {
if (oa[i].getDatabase() == db) {
try {
oa[i].setReadOnly(true);
oa[i].setReadOnlyDefault(true);
} catch (Exception e) {
//the connection is during transaction...
}
}
}
//the implementation of Database cannot turn to writable,
//close it...
db.close(Database.CLOSEMODE_COMPACT);

Migration of blobs from database to the file system in jackrabbit

As being proposed in the previous discussion Using file system instead of database to store pdf files in jackrabbit
we can use FileDataStore to store blob files in the file system instead of database (i my case have stored ~ 100 kb size pdfs).
The following problem I have faced is dealing with files that have been previously stored in blobstore and I want them to be accessible after switching to FileDataStore.
After adding FileDataStore support to the repository.xml
when using JcrUtils method getOrAddNode i get ItemExistsException:
public static Node getOrAddNode(Node parent, String name)
throws RepositoryException {
if (parent.hasNode(name)) {
return parent.getNode(name);
} else {
return parent.addNode(name);
}
}
e.g. parent.hasNode(name) returns false (it seems the item doesn't exist)
but then we fall in to the code parent.addNode(name) which consequently throws ItemExistsException.
Any help?
Is it necessary to proceed the migration of blobs to the FileDataStore or there is kind of configuration that jackrabbit could search for blobs in different locations at the same time: in my case mysql database and filesystem.
Some comments:
I have found at least several ways that could help do the migration job:
spec http://wiki.apache.org/jackrabbit/BackupAndMigration
tells about using JCR API (Session.exportSystemView(..) and then Session.importXML(..) ), using RepositoryCopier API etc.
jackrabbit-jcr-import-export-tool (see http://svn.apache.org/repos/asf/jackrabbit/sandbox/jackrabbit-jcr-import-export-tool/README.txt)
using jackrabbit standalone server (http://jackrabbit.apache.org/standalone-server.html)
It might be possible that there is a repository corruption. That is, the node contains a child node entry for the given name (the node you want to add), but the child node itself doesn't exist. Specially in older version of Jackrabbit you could get into this situation if multiple sessions concurrently tried to change the same nodes.
To fix such corruption problems, the bundle db persistence managers support a consistency check & fix feature. You would need to set those options in the repository.xml and workspace.xml files, and restart Jackrabbit. Once fixed, you can disable those options again.
There is also a way to fix such problems at runtime, by setting the system property org.apache.jackrabbit.autoFixCorruptions to true, and then traverse over all nodes in the repository.

h2 (embedded mode ) database files problem

There is a h2-database file in my src directory (Java, Eclipse): h2test.db
The problem:
starting the h2.jar from the command line (and thus the h2 browser interface on port 8082), I have created 2 tables, 'test1' and 'test2' in h2test.db and I have put some data in them;
when trying to access them from java code (JDBC), it throws me "table not found exception". A "show tables" from the java code shows a resultset with 0 rows.
Also, when creating a new table ('newtest') from the java code (CREATE TABLE ... etc), I cannot see it when starting the h2.jar browser interface afterwards; just the other two tables ('test1' and 'test2') are shown (but then the newly created table 'newtest' is accessible from the java code).
I'm inexperienced with embedded databases; I believe I'm doing something fundamentally wrong here. My assumption is, that I'm accessing the same file - once from the java app, and once from the h2 console-browser interface. I cannot seem to understand it, what am I doing wrong here?
EDIT: as requested, adding some code:
Java code:
Class.forName("org.h2.Driver");
String url = "jdbc:h2:" + "db/h2test.db";
String user = "aeter";
String password = "aeter";
Connection conn = DriverManager.getConnection(url, user, password);
PreparedStatement ps2 = conn.prepareStatement("Show tables;");
ResultSet rs = ps2.executeQuery();
This resultset has 0 rows (no tables), instead of showing me the 2 tables.
H2 Console-browser interface settings:
Settings: Generic h2(embedded)
driver class: org.h2.Driver
JDBC URL: jdbc:h2:../../workspace/project_name/src/db/h2test.db
user name: aeter
password: aeter
EDIT2: I copied the database to a new folder. Now the db file in the new folder is shown with the 'newtest' table (from the java code) and with the 'test1' and 'test2' tables (from the console-browser h2 interface) - exactly the same way the older db file was shown. So the problem persists with the copy of the db file.
For embedded mode, you'll need to check the path. For example, use a path relative to your home directory:
"jdbc:h2:file:~/db/h2test.db"
To be sure, use a full path:
"jdbc:h2:file:/users/aeter/db/h2test.db"
For convenience, append ;IFEXISTS=TRUE to avoid creating spurious database files.
See Connecting to a Database using JDBC for more.
H2 Server URLs are relative to the -baseDir specified as a parameter to main().
Also there can be a problem if you use some special parameters in your JDBC url, the database file name can differ for various cases.
In my case, I had two URLs:
jdbc:h2:~/XXX;MVCC=FALSE;MV_STORE=FALSE
jdbc:h2:~/XXX
This first case created XXX.h2.db file, the second one XXX.mv.db, beware.
Also you can like this
"jdbc:h2:file:db/h2test.db"
then java looks db folder from project folder
->projectName // project folder
-->src // src folder
-->db // here your database folder
-->....
If you are using Hibernate try this in hibernate.cfg.xml file:
<property name="connection.url">jdbc:h2:file:db/h2test</property>
without *.db extension at the end

Categories