Commit 044814c7 authored by igoshin's avatar igoshin
Browse files

#14051display sql error.

parent e7cdf568
......@@ -18,6 +18,7 @@ package org.genesys2.anno.gui;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
......@@ -51,17 +52,7 @@ import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.*;
import org.genesys2.anno.converter.RowConverter;
import org.genesys2.anno.model.Column;
import org.genesys2.anno.model.ColumnDef;
......@@ -501,18 +492,25 @@ public class SheetDisplay extends Composite {
});
}
private void executeSqlQuery(String query, DSW dsw) {
String url = ((JdbcDataSourceSheet) dsw.getDataSourceSheet()).getDatabaseSettings().getUrl();
String user = ((JdbcDataSourceSheet) dsw.getDataSourceSheet()).getDatabaseSettings().getUser();
String password = ((JdbcDataSourceSheet) dsw.getDataSourceSheet()).getDatabaseSettings().getPassword();
IDataSourceSheet currentSheet = dsw.getDataSourceSheet();
final List<Object[]> rows = jdbcRowReader.getRows(query, url, user, password);
if (rows != null) {
currentSheet.updateData(rows);
}
}
private void executeSqlQuery(String query, DSW dsw) {
IDataSourceSheet currentSheet = dsw.getDataSourceSheet();
String url = ((JdbcDataSourceSheet) currentSheet).getDatabaseSettings().getUrl();
String user = ((JdbcDataSourceSheet) currentSheet).getDatabaseSettings().getUser();
String password = ((JdbcDataSourceSheet) currentSheet).getDatabaseSettings().getPassword();
final List<Object[]> rows;
try {
rows = jdbcRowReader.getRows(query, url, user, password);
if (rows != null) {
currentSheet.updateData(rows);
}
} catch (SQLException e) {
showMessageBox("SQL error", e);
_log.error(e.getMessage());
}
}
protected void doDoubleClickOnRow(Object[] row) {
IDataSourceSheet dataSourceSheet = getDataSourceSheet();
......
......@@ -2,12 +2,10 @@ package org.genesys2.anno.reader;
import org.apache.log4j.Logger;
import org.eclipse.swt.custom.CTabItem;
import org.genesys2.anno.util.ConnectionUtils;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
......@@ -15,38 +13,31 @@ import java.util.List;
public class JDBCRowReader {
private static final Logger _log = Logger.getLogger(JDBCRowReader.class);
public List<Object[]> getRows(String query, String url, String user, String password) {
public List<Object[]> getRows(String query, String url, String user, String password) throws SQLException {
List<Object[]> rows= new ArrayList<Object[]>();
List<Object[]> rows = new ArrayList<Object[]>();
Connection conn = null;
try {
conn = ConnectionUtils.getConnection(url, user, password);
Connection conn = ConnectionUtils.getConnection(url, user, password);
PreparedStatement ps = conn.prepareStatement(query);
ResultSet res = ps.executeQuery();
ResultSetMetaData metaData = res.getMetaData();
PreparedStatement ps = conn.prepareStatement(query);
ResultSet res = ps.executeQuery();
ResultSetMetaData metaData = res.getMetaData();
int columnCount = metaData.getColumnCount();
ArrayList<String> columns = new ArrayList<String>();
for (int i = 1; i <= columnCount; i++) {
columns.add(metaData.getColumnName(i));
}
rows.add(columns.toArray());
while (res.next()) {
List<Object> row= new ArrayList<Object>();
for (String columnName:columns) {
Object val = res.getObject(columnName);
row.add(val);
}
rows.add(row.toArray());
int columnCount = metaData.getColumnCount();
ArrayList<String> columns = new ArrayList<String>();
for (int i = 1; i <= columnCount; i++) {
columns.add(metaData.getColumnName(i));
}
rows.add(columns.toArray());
while (res.next()) {
List<Object> row = new ArrayList<Object>();
for (String columnName : columns) {
Object val = res.getObject(columnName);
row.add(val);
}
return rows;
} catch (Exception e) {
_log.error(e.getMessage());
} finally {
ConnectionUtils.close(conn);
rows.add(row.toArray());
}
return null;
ConnectionUtils.close(conn);
return rows;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment