h2

Creating separate data source for my session spring using JDBC and spring data jpa in spring boot

限于喜欢 提交于 2019-12-08 06:11:17
问题 I am a newbie in spring-boot and i want to configure my spring session with jdbc using h2 database, but it does not create a database and table in my h2 embedded database, it creates it in the PostgreSQL, using the PostgreSQL data source i configured in my applications properties file. How do i make my spring app use my embedded h2 db for storing sessions only while not conflicting with the PostgreSQL data source for my JPA https://github.com/eshiett1995/SessionProject. i would love if

org.h2.jdbc.JdbcSQLException: The object is already closed

馋奶兔 提交于 2019-12-08 05:27:05
问题 For the life of me I cannot see how it "is already closed" import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; public class RsetTest2 { public static void main(String[] args) throws Exception { String dbpath = "jdbc:h2:c:/mydb;IFEXISTS=TRUE;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE"; Connection conn = null; System.setProperty("h2.bindAddress", "127.0.0.1"); Class.forName("org.h2.Driver"); conn = DriverManager.getConnection(dbpath, "sa

H2 “OTHER” data type throws Exception when storing String or Boolean

这一生的挚爱 提交于 2019-12-08 05:02:36
I understand that the OTHER data type can store any Serializable object. However when I try to store an instance of String or Boolean it fails with an exception. Is this a misunderstanding on my part, or a bug in H2? Here's repro code. import org.h2.jdbc.JdbcSQLException; import java.io.Serializable; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; public class ScratchSpace { public static void main(String[] args) throws SQLException, ClassNotFoundException { Class.forName("org.h2.Driver"); Connection conn =

SQL commands not compliable by H2

北慕城南 提交于 2019-12-08 04:51:11
问题 The following SQL commands are actually for MySQL. I am not a SQL expert and do not know much about H2. My Spring app throws an exception because the user_roles table can not be created. It has a problem with the fk_username_idx : DROP TABLE IF EXISTS users; DROP TABLE IF EXISTS user_roles; CREATE TABLE users ( userid VARCHAR(5) NOT NULL, username VARCHAR(45) NOT NULL , password VARCHAR(60) NOT NULL , enabled TINYINT NOT NULL DEFAULT 1 , PRIMARY KEY (userid)); CREATE TABLE user_roles ( user

User-defined variables set by parameters

六眼飞鱼酱① 提交于 2019-12-08 04:05:09
问题 The SQL is am using is: SET @person1_id = ?; SET @person2_id = ?; SET @safety_factor = ?; SELECT * FROM table WHERE person1 = @person1_id AND person2 = @person2_id AND safety_factor = @safety_factor; That's not the exact code, but shows what i'm trying to do The way I then input parameters is Statement stmt = connection.prepareStatement(*script*) stmt.setLong(1, person1.id) stmt.setLong(2, person2.id) stmt.setBigDecimal(3, safetyFactor) I'm using variables in the sql because the values are

Remote connection to a H2 database in server mode with DBCP pooling

时光毁灭记忆、已成空白 提交于 2019-12-08 03:29:58
问题 I'm trying to create an embedded H2 server which I could also access remotly and also use Tomcat DBCP Pooling. Here is my code to produce the dataSource : @Produces @ApplicationScoped public DataSource getDataSource() throws NamingException, SQLException { dataSource = new BasicDataSource(); dataSource.setDriverClassName("org.h2.jdbcx.JdbcDataSource"); dataSource.setUrl("jdbc:h2:/tmp/myapp"); dataSource.setUsername("sa"); dataSource.setPassword(""); dataSource.setMaxActive(100); dataSource

Selecting random rows from a big table in H2 database

断了今生、忘了曾经 提交于 2019-12-07 21:44:48
问题 I have a big table in my database (potentially millions of records) and I need to select #X random rows (let's say #X between 10 and 50) , but I need this query to be as optimal as possible. The table looks like this: CREATE TABLE sample ( id bigint auto_increment PRIMARY KEY, user_id bigint NOT NULL, screen_name VARCHAR NOT NULL, ... ); I've searched around and I found answers like this: SELECT * FROM sample ORDER BY RAND() limit X. But It looks to me that this will fetch the full table then

H2 createTcpServer() does not create server?

血红的双手。 提交于 2019-12-07 19:26:22
after reading the H2 documentation , I wrote this simple application to create a H2 database in a local directory: public static void main(String[] args) throws SQLException { String path = "C:/Temp/H2/"; File fpath = new File(path); fpath.mkdirs(); FileUtils.recursiveDelete(fpath); String dbName = "tata"; String connection = "jdbc:h2:file:" + path + dbName; Server server = Server.createTcpServer(connection); server.start(); server.stop(); } This program runs fine, but when I check in the target directory, the database is not there... (i am using release 1.3.161) You need to actually access

H2 script STRINGDECODE

北城余情 提交于 2019-12-07 18:42:46
MYSQL 导出 到 H2 近期想将开发中系统的数据库随身携带,以便随时学习。最好的办法当然是将数据库随身携带,所以想到了导出到H2中。H2的压缩模式很厉害,在MYSQL中1G左右的空间,压缩后占用6、7M。非常适合将数据导出H2中随时启动以查看表结构。 由于MYSQL的导出SQL不标准,无法直接导入到H2中,所以我写了如下脚本将将MYSQL转化为H2脚本。 mysqldump --add-drop-table=FALSE --add-locks=FALSE --lock-tables=FALSE --quote-names=FALSE --set-charset=FALSE --comments=FALSE -uroot -proot riil_product > mysql.sql sed '/^\/\*!.*\*\/;/d;s/[ ]*ENGINE=.*DEFAULT[ ]CHARSET=[^ ^;]*[ ]*//g;s/double(\([0-9]*\),\([0-9]*\))/number(\1,\2)/g;s/ON UPDATE CURRENT_TIMESTAMP//g;s/ USING BTREE//g;/^\/\*!/,/\*\//d;/^SET/d;' mysql.sql|sed '/CREATE TABLE \([^ ]*\) (/{h};/^)COMMENT=

How to persist a Map<String, List<Object>> in Hibernate

风流意气都作罢 提交于 2019-12-07 17:50:36
问题 I've got a Map containing MyObject instances. The MyObject class uses JPA to persist its fields: @OneToMany(cascade = CascadeType.ALL) @LazyCollection(LazyCollectionOption.FALSE) private Map<String, MyObject> results = new HashMap<String, MyObject>(); We changed the value stored by the Map to a List : private Map<String, List<MyObject>> results = new HashMap<String, List<MyObject>>(); But upon launching we receive a stack trace: Caused by: org.hibernate.AnnotationException: Use of @OneToMany