-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementing interface for table creation
- Loading branch information
1 parent
8fd408e
commit 82723e4
Showing
5 changed files
with
75 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package excel2db.service; | ||
|
||
import java.sql.SQLException; | ||
|
||
public interface CreateTable { | ||
|
||
public void createTable () throws SQLException; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/java/excel2db/service/impl/CreateTablePostgresImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package excel2db.service.impl; | ||
|
||
import excel2db.excel2db; | ||
import excel2db.service.CreateTable; | ||
|
||
import java.sql.PreparedStatement; | ||
import java.sql.SQLException; | ||
|
||
public class CreateTablePostgresImpl implements CreateTable { | ||
|
||
public void createTable() throws SQLException | ||
{ | ||
String sqlTableDropStatement = "DROP TABLE IF EXISTS excel2db;"; | ||
|
||
|
||
StringBuilder sqlTableCreateStatement = new StringBuilder(); | ||
|
||
sqlTableCreateStatement.append("CREATE TABLE excel2db("); | ||
|
||
|
||
for (String headerColumnName : excel2db.sheetEntityManager.header.keySet()) { | ||
sqlTableCreateStatement.append("\"" + headerColumnName + "\"" + " text, "); | ||
} | ||
|
||
|
||
sqlTableCreateStatement.setLength(sqlTableCreateStatement.length() - 2); | ||
|
||
sqlTableCreateStatement.append(") WITH (OIDS=FALSE);"); | ||
|
||
|
||
PreparedStatement pstmtDrop = excel2db.connection.prepareStatement(sqlTableDropStatement); | ||
pstmtDrop.execute(); | ||
|
||
PreparedStatement pstmtCreate = excel2db.connection.prepareStatement(sqlTableCreateStatement.toString()); | ||
pstmtCreate.execute(); | ||
|
||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters