hsqldbconnection.java

来自「Spring framework basic tutorial using Ja」· Java 代码 · 共 36 行

JAVA
36
字号
package tutorial.model;

import java.sql.Connection;

import org.hsqldb.jdbc.jdbcDataSource;

public class HSQLDBConnection implements DBConnection {

	@Override
	public Connection getConnection() {
		// Exceptions may occur
		try {

			// get a DataSource object and set the URL
			// 'testfiles' in the URL is the name of the database
			jdbcDataSource dataSource = new jdbcDataSource();

			dataSource.setDatabase("jdbc:hsqldb:file:testfiles");

			// Connect to the database
			// It will be create automatically if it does not yet exist
			// "sa" is the user name and "" is the (empty) password
			Connection conn = dataSource.getConnection("SA", "");			
			return conn;
		} catch (Exception e) {

			// Print out the error message
			System.out.println(e);
			e.printStackTrace();
		}
		return null;

	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?