데이터베이스에 연결하는 데 사용할 수있는 최대 절전 모드 utitliy가 있습니다. 모든 테이블을 나열하고 "테이블 + 데이터 생성"을위한 sql 스크립트를 생성하고 * .sql 파일로 저장 하시겠습니까? SQL 등의 데이터베이스에서SQL 스크립트를 생성
6
A
답변
7
데이터 내보내기
사용 liquibase 오픈 소스 프로젝트
LiquiBase는 오픈 소스 (LGPL), 추적, 관리 및 데이터베이스 변경을 적용하기위한 데이터베이스 독립적 인 라이브러리를. 모든 데이터베이스 변경 (구조 및 데이터)은 XML 기반 서술 방식으로 저장되고 소스 제어에 체크인됩니다. 그냥 모든 엔티티 클래스와이 클래스를 구성하고/dropTableScript 만들 전화 :
만들고 주어진 JPA 엔티티
우리는 드롭을 생성하고 문을 만들려면이 코드를 사용하기위한 스크립트를 드롭 생성합니다.
필요하다면 persitence.xml과 persitance unit name을 사용할 수 있습니다. 그냥 라고 말하면 코드도 게시합니다.
import java.util.Collection; import java.util.Properties; import org.hibernate.cfg.AnnotationConfiguration; import org.hibernate.dialect.Dialect; import org.hibernate.ejb.Ejb3Configuration; /** * SQL Creator for Tables according to JPA/Hibernate annotations. * * Use: * * {@link #createTablesScript()} To create the table creationg script * * {@link #dropTablesScript()} to create the table destruction script * */ public class SqlTableCreator { private final AnnotationConfiguration hibernateConfiguration; private final Properties dialectProps; public SqlTableCreator(final Collection> entities) { final Ejb3Configuration ejb3Configuration = new Ejb3Configuration(); for (final Class entity : entities) { ejb3Configuration.addAnnotatedClass(entity); } dialectProps = new Properties(); dialectProps.put("hibernate.dialect", "org.hibernate.dialect.SQLServerDialect"); hibernateConfiguration = ejb3Configuration.getHibernateConfiguration(); } /** * Create the SQL script to create all tables. * * @return A {@link String} representing the SQL script. */ public String createTablesScript() { final StringBuilder script = new StringBuilder(); final String[] creationScript = hibernateConfiguration.generateSchemaCreationScript(Dialect .getDialect(dialectProps)); for (final String string : creationScript) { script.append(string).append(";\n"); } script.append("\ngo\n\n"); return script.toString(); } /** * Create the SQL script to drop all tables. * * @return A {@link String} representing the SQL script. */ public String dropTablesScript() { final StringBuilder script = new StringBuilder(); final String[] creationScript = hibernateConfiguration.generateDropSchemaScript(Dialect .getDialect(dialectProps)); for (final String string : creationScript) { script.append(string).append(";\n"); } script.append("\ngo\n\n"); return script.toString(); } }
관련 문제
- 1. 명령 줄에서 SQL 서버 스크립트를 생성 하시겠습니까?
- 2. 스크립트는 "/ 생성 스크립트를"레일
- 3. 안전한 방법으로 Sql 스크립트를 묶기
- 4. 빌드시 Ef4 CodeFirst로 db sql 스크립트를 생성 할 수 있습니까?
- 5. 기존 데이터베이스에서 SQL 스크립트를 생성 할 수있는 방법이 있습니까?
- 6. 스크립트 생성 SQL Server 2008
- 7. 자바 스크립트를 동적으로 생성 하시겠습니까?
- 8. Ruby에서 sql 스크립트를 실행하십시오.
- 9. Erwin Forward Engineer는 T-SQL 테이블 생성 스크립트를 생성 할 수 있습니까?
- 10. Linq to Sql - SQL 생성
- 11. SQL 스크립트에서 다른 SQL 스크립트를 참조 하시겠습니까?
- 12. SQL 스크립트를 사용하여 SQL Server 데이터베이스 업데이트
- 13. SQL Server 2008에서 SQL Server 2008 Express로 스크립트를 생성 할 수 있습니까?
- 14. 자바 스크립트에서 SQL 스크립트를 사용
- 15. SQL 서버 스크립트를 MySQL로 변환
- 16. 쿼리에서 SQL 스크립트를 생성하는 방법
- 17. 삽입 스크립트를 작성하는 SQL 스크립트
- 18. bash에서 .sql 스크립트를 실행하는 방법
- 19. 생성 SQL 스키마는 XML
- 20. 생성 SQL 웹 사이트
- 21. SQL 서버에서 조합 생성
- 22. SQL 쿼리 생성
- 23. SQL Server에서 별칭 생성
- 24. SQL 서버에서 시퀀스 생성
- 25. SQL 서버 데이터 생성
- 26. 신속하게 SQL 2008 데이터베이스를 기반으로 ascii text sql 스크립트를 생성합니다.
- 27. 슈퍼/서브 스크립트를 이용한 PHP 이미지 생성
- 28. 쉘 스크립트를 사용하여 임의의 파일 생성
- 29. 쉘 스크립트를 사용하여 XML 파일을 생성
- 30. 자바 스크립트를 사용하여 오디오 비디오 (ogg) 생성
이 경우 SQL 스크립트로 변환하려면 도메인 객체가 있어야합니다. 내가 원하는 건. 그냥 데이터베이스 서버에 연결하고 모든 테이블을 나열하고 테이블 생성 스크립트를 생성합니다. 가능한? – cometta
오른쪽 엔티티가 필요합니다 (perstiance.xml 또는리스트에서> 그렇지 않으면 주어진 JDBC 연결에서 ddl 스키마를 포함하는 데이터를 내보내는 liquibase를 사용할 수 있습니다. 더 많은 생각을 할 수 있습니다 (스키마 diffing, 패치 ...). 다른 방법은 우리의 absoulte 좋아하는 직장에서 스위스 군용 칼 DBVisualizer를 사용하는 것입니다 (개인용 버전에서 무료!, java로 작성된 JDBC로 작성) –
H2000
안녕하세요, dbvisualizer를 사용하려고했는데 볼 수 있습니다. -> 테이블,보기 "내 데이터베이스에 대한 테이블 및 데이터를 SQL 스크립트로 내보내는 방법 – cometta