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
Related
This is the class where I connect sqlite
public static Connection ConnectDB() {
try {
Class.forName("org.sqlite.JDBC");
Connection con= DriverManager.getConnection("jdbc:sqlite:C:\\Users\\abh\\eclipse-workspace \\Training\\Database.db");
return con;
}
catch (Exception e) {
JOptionPane.showMessageDialog(null,e);
return null;
}
}
The jar file inside the project folder name is sqlite-jdbc-3.7.2 I'm confused whether it's because of the version or if it's from my database created in sqlite
SQLite is a pretty good database platform, I highly doubt it's the problem as is the JDBC version your using as well.
The Connection method you presented does indeed work but you need to keep in mind that the connection has nothing to do with tables. It has everything to towards a connection to a particular SQLite database file and if the path doesn't exist to get to the database file specified, then it simply can not find that database. If the path does exist, and local system permissions allow it, and the database file does not exist, then the connection call will automatically create the database file specified but it will be empty. Never the less, the connection is now made and ready for a database Table to be either Created or Accessed via a query (providing there is actual data in the table).
If there was an error regards to the connection then you would receive a Message Box on the screen, and if you do then it's probably because of the whitespace that exists in the specified database path between eclipse-workspace and \\Training:
"jdbc:sqlite:C:\\Users\\abh\\eclipse-workspace \\Training\\Database.db"
Edit: Oh...as already specified by #lazylead :)
On a side: It's not a good idea to hard-code the path to your database file. This will never be the path when the application is run in the real world.
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.
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
Ok, I am reposting this question because it really drives me crazy.
I have enterprise.wsdl downloaded from salesforce and generated to some jars.
I build path those jars to my Android project in Eclipse.
Here is my code:
ConnectorConfig config = new ConnectorConfig();
config.setAuthEndpoint(authEndPoint);
config.setUsername(userID);
config.setPassword(password + securityToken);
config.setCompression(true);
con = new EnterpriseConnection(config);
con.setSessionHeader(UserPreference.getSessionID(mContext));
String sql = "SELECT something FROM myNameSpace__myCustomObject__c";
con.query(sql);
but it returns me this error:
[InvalidSObjectFault [ApiQueryFault [ApiFault
exceptionCode='INVALID_TYPE' exceptionMessage='sObject type 'abc__c'
is not supported.'] row='-1' column='-1' ]]
I am pretty sure that my userID has been assigned with profile that has read, edit access to that custom object.
My code also can query standard object.
Anyone can advise me what could be wrong?
From what I know there are three reasons it may give this error.
1. User permission which you said is setup correctly.
2. Do you have the custom object deployed to the org where you are trying to establish the connection?
3. Check the enterprise WSDL if it contains the custom object name which you are trying to query.
Hope it helps.
I am attempting to combine two disparate data sources into one MBO. The sybase documentation states that you have to develop a custom result set filter in java. Ok. No big deal. I am somewhat familiar with JDBC Rowsets so I think I can probably handle this. So I go grab JConnect 7 and am attempting to use the JDBC driver in my result set filter to get a result set that I can use to filter the data set returned from the web service I am connecting to. I have tested my connection with the simple test below:
try
{
DriverManager.registerDriver((Driver)Class.forName("com.sybase.jdbc4.jdbc.SybDriver").newInstance());
Connection conn = DriverManager.getConnection("jdbc:sybase:Tds:localhost:5500", "dba", "sql");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("Select * from traveler where traveler_id = 1");
while (rs.next())
{
System.out.println(rs.getRow());
}
} catch (Exception se)
{
se.printStackTrace();
}
Of which I get a rowcount of one back, which is what I am expecting. The problem is when I implement this same code in the ResultSet filter class, and attempt to preview it in the MBO, I get the following error in the eclipse debug console (distilled for clarity):
22:14:20 [ERROR] [ExecuteSection]: Execution error
java.lang.reflect.InvocationTargetException...
[...]
Caused by: java.lang.UnsatisfiedLinkError: no dbjodbc11 in java.library.path
This looks like a classpath issue, but I have the Jconnect jar in my build path, and that is verified by the fact that my little test runs successfully. Is this an eclipse issue.. is eclipse using a different classpath when executing code for the Mobile workspace project?
Can't remember the exact path right now, but there is a third-party lib folder under the <SybaseInstallation>/UnwiredWorkspace folder. Try adding your jar there.