Package net.sourceforge.squirrel_sql.fw.sql

Examples of net.sourceforge.squirrel_sql.fw.sql.ISQLConnection


   * @return
   * @throws Exception
   */
  public static ResultSet executeQuery(ISession session, String sql) throws SQLException
  {
    ISQLConnection sqlcon = session.getSQLConnection();
    if (sqlcon == null || sql == null)
    {
      return null;
    }
    Statement stmt = null;
    ResultSet rs = null;

    Connection con = sqlcon.getConnection();
    try
    {
      if (DialectFactory.isMySQL(session.getMetaData()))
      {
        stmt = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
View Full Code Here


  }

  public static ITableInfo getTableInfo(ISession session, String schema, String tableName)
        throws SQLException, MappingException, UserCancelledOperationException
  {
    ISQLConnection con = session.getSQLConnection();
    // Currently, as of milestone 3, Axion doesn't support "schemas" like
    // other databases. So, set the schema to emtpy string if we detect
    // an Axion session.
    if (con.getSQLMetaData().getDriverName().toLowerCase().startsWith("axion"))
    {
      schema = "";
    }
    String catalog = null;
    // MySQL uses catalogs and not schemas
View Full Code Here

   * @throws SQLException
   */
  public static void deleteDataInExistingTable(ISession session, String catalogName, String schemaName,
        String tableName) throws SQLException, UserCancelledOperationException
  {
    ISQLConnection con = session.getSQLConnection();
    boolean useTrunc = PreferencesManager.getPreferences().isUseTruncate();
    String fullTableName = getQualifiedObjectName(
       session, catalogName, schemaName, tableName, DialectFactory.DEST_TYPE);
    String truncSQL = "TRUNCATE TABLE " + fullTableName;
    String deleteSQL = "DELETE FROM " + fullTableName;
View Full Code Here

    result.append(" ( ");
    result.append("\n");
    TableColumnInfo colInfo = null;
    try
    {
      ISQLConnection sourceCon = prov.getCopySourceSession().getSQLConnection();
      TableColumnInfo[] colInfoArr = sourceCon.getSQLMetaData().getColumnInfo(ti);
      if (colInfoArr.length == 0)
      {
        // i18n[DBUtil.error.nocolumns=Table '{0}' in schema '{1}' has
        // no columns to copy]
        String msg = s_stringMgr.getString("DBUtil.error.nocolumns", new String[]
View Full Code Here

    ISession destSession = prov.getCopyDestSession();
    if (sourceSession == null || destSession == null)
    {
      return;
    }
    ISQLConnection sourceCon = sourceSession.getSQLConnection();
    ISQLConnection con = destSession.getSQLConnection();
    TableColumnInfo[] colInfoArr = null;
    try
    {
      colInfoArr = sourceCon.getSQLMetaData().getColumnInfo(ti);
    } catch (SQLException e)
View Full Code Here

  public static boolean dropTable(String tableName, String schemaName, String catalogName, ISession session,
        boolean cascade, int sessionType) throws UserCancelledOperationException
  {
    boolean result = false;
    ISQLConnection con = session.getSQLConnection();
    String table = getQualifiedObjectName(session, catalogName, schemaName, tableName, sessionType);
    String dropsql = "DROP TABLE " + table;
    if (cascade)
    {
      dropsql += " CASCADE";
View Full Code Here

     */
    private void _execute() {
     
      // Create column list
      String columnList = createColumnList();
      ISQLConnection conn = session.getSQLConnection();
     
      StringBuffer insertSQL = new StringBuffer();
      insertSQL.append("insert into ").append(table.getQualifiedName());
      insertSQL.append(" (").append(columnList).append(") ");
      insertSQL.append("VALUES ");
      insertSQL.append(" (").append(getQuestionMarks(getColumnCount())).append(")");
     
      PreparedStatement stmt = null;
      boolean autoCommit = false;
    int rows = 0;
    boolean success = false;
      try {
        DataImportPreferenceBean settings = PreferencesManager.getPreferences();
        importer.open();
        if (skipHeader)
          importer.next();
        autoCommit = conn.getAutoCommit();
        conn.setAutoCommit(false);
       
        if (settings.isUseTruncate()) {
          String sql = "DELETE FROM " + table.getQualifiedName();
          stmt = conn.prepareStatement(sql);
          stmt.execute();
          stmt.close();
        }
       
        stmt = conn.prepareStatement(insertSQL.toString());
        //i18n[ImportDataIntoTableExecutor.importingDataInto=Importing data into {0}]
        ProgressBarDialog.getDialog(session.getApplication().getMainFrame(), stringMgr.getString("ImportDataIntoTableExecutor.importingDataInto", table.getSimpleName()), false, null);
        int inputLines = importer.getRows();
        if (inputLines > 0) {
          ProgressBarDialog.setBarMinMax(0, inputLines == -1 ? 5000 : inputLines);
        } else {
          ProgressBarDialog.setIndeterminate();
        }
     
        while (importer.next()) {
          rows++;
          if (inputLines > 0) {
            ProgressBarDialog.incrementBar(1);
          }
          stmt.clearParameters();
          int i = 1;
          for (TableColumnInfo column : columns) {
            String mapping = getMapping(column);
            try {
              if (SpecialColumnMapping.SKIP.getVisibleString().equals(mapping)) {
                continue;
              } else if (SpecialColumnMapping.FIXED_VALUE.getVisibleString().equals(mapping)) {
                bindFixedColumn(stmt, i++, column);
              } else if (SpecialColumnMapping.AUTO_INCREMENT.getVisibleString().equals(mapping)) {
                bindAutoincrementColumn(stmt, i++, column, rows);
              } else if (SpecialColumnMapping.NULL.getVisibleString().equals(mapping)) {
                stmt.setNull(i++, column.getDataType());
              } else {
                bindColumn(stmt, i++, column);
              }
            } catch (UnsupportedFormatException ufe) {
              // i18n[ImportDataIntoTableExecutor.wrongFormat=Imported column has not the required format.\nLine is: {0}, column is: {1}]
              JOptionPane.showMessageDialog(session.getApplication().getMainFrame(), stringMgr.getString("ImportDataIntoTableExecutor.wrongFormat", new Object[] { rows, i-1 }));
              throw ufe;
            }
          }
          stmt.execute();
        }
        conn.commit();
        conn.setAutoCommit(autoCommit);
        importer.close();
       
        success = true;
       
      } catch (SQLException sqle) {
        //i18n[ImportDataIntoTableExecutor.sqlException=A database error occured while inserting data]
        //i18n[ImportDataIntoTableExecutor.error=Error]
        JOptionPane.showMessageDialog(session.getApplication().getMainFrame(), stringMgr.getString("ImportDataIntoTableExecutor.sqlException"), stringMgr.getString("ImportDataIntoTableExecutor.error"), JOptionPane.ERROR_MESSAGE);
        log.error("Database error", sqle);
      } catch (UnsupportedFormatException ufe) {
        try {
            conn.rollback();
        } catch (Exception e) {
            log.error("Unexpected exception while attempting to rollback: "
                      +e.getMessage(), e);
        }
        log.error("Unsupported format.", ufe);
View Full Code Here

        } else {
          // When the user pastes on a TABLE label which is located under a
          // schema/catalog, build the schema DatabaseObjectInfo.
          if (DatabaseObjectType.TABLE_TYPE_DBO.equals(dbObjs[0].getDatabaseObjectType())) {
            IDatabaseObjectInfo tableLabelInfo = dbObjs[0];
            ISQLConnection destCon = destSession.getSQLConnection();
            SQLDatabaseMetaData md = null;
            if (destCon != null) {
              md = destCon.getSQLMetaData();
            }
            IDatabaseObjectInfo schema =
              new DatabaseObjectInfo(null,
                           tableLabelInfo.getSchemaName(),
                           tableLabelInfo.getSchemaName(),
View Full Code Here

  public List<ObjectTreeNode> createChildren(ISession session, ObjectTreeNode parentNode)
        throws SQLException
  {
    final List<ObjectTreeNode> childNodes = new ArrayList<ObjectTreeNode>();
    final IDatabaseObjectInfo parentDbinfo = parentNode.getDatabaseObjectInfo();
    final ISQLConnection conn = session.getSQLConnection();
    final SQLDatabaseMetaData md = session.getSQLConnection().getSQLMetaData();
    final String catalogName = parentDbinfo.getCatalogName();
    final String schemaName = parentDbinfo.getSchemaName();
    final ObjFilterMatcher filterMatcher = new ObjFilterMatcher(session.getProperties());

    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try
    {
      if (s_log.isDebugEnabled()) {
        s_log.debug("createChildren: running SQL - "+SQL);
        s_log.debug("createChildren: with SYNONYM_NAME = "+filterMatcher.getSqlLikeMatchString());
        s_log.debug("createChildren: with schema = "+schemaName);
        s_log.debug("createChildren: with catalog = "+catalogName);
      }
     
      pstmt = conn.prepareStatement(SQL);
     
      pstmt.setString(1, filterMatcher.getSqlLikeMatchString());
      pstmt.setString(2, schemaName);
      pstmt.setString(3, catalogName);
     
View Full Code Here

  /**
   * Execute this command. Place the "create table" script in the SQL entry panel.
   */
  public void execute() throws BaseException
  {
    final ISQLConnection conn = _session.getSQLConnection();
    final StringBuffer buf = new StringBuffer(2048);
    final String sep = " " + _session.getQueryTokenizer().getSQLStatementSeparator();

    try
    {
      final Statement stmt = conn.createStatement();
      try
      {
        IObjectTreeAPI api = _session.getSessionInternalFrame().getObjectTreeAPI();
        IDatabaseObjectInfo[] dbObjs = api.getSelectedDatabaseObjects();
        for (int i = 0; i < dbObjs.length; ++i)
View Full Code Here

TOP

Related Classes of net.sourceforge.squirrel_sql.fw.sql.ISQLConnection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.