version 1.19, 2004/05/11 09:06:38
|
version 1.27, 2004/07/09 10:26:38
|
Line 13
|
Line 13
|
* rogo |
* rogo |
*/ |
*/ |
|
|
|
|
import java.sql.*; |
import java.sql.*; |
import java.text.DateFormat; |
import java.text.DateFormat; |
|
import java.text.ParseException; |
import java.util.*; |
import java.util.*; |
|
|
import com.fmi.jdbc.*; |
import com.fmi.jdbc.*; |
Line 65 import com.fmi.jdbc.*;
|
Line 65 import com.fmi.jdbc.*;
|
*/ |
*/ |
public class DBBean |
public class DBBean |
{ |
{ |
|
private boolean useNormanToUnicodeMapper = false; |
Connection connection; |
Connection connection; |
String url = ""; |
String url = ""; |
DatabaseMetaData dbMetaData; |
DatabaseMetaData dbMetaData; |
Line 188 public class DBBean
|
Line 189 public class DBBean
|
{ |
{ |
// setup the properties |
// setup the properties |
java.util.Properties prop = new java.util.Properties(); |
java.util.Properties prop = new java.util.Properties(); |
prop.put("charSet", "Cp1256"); |
// prop.put("charSet", "MacCentralEurope"); |
prop.put("user", user); |
prop.put("user", user); |
prop.put("password", passwd); |
prop.put("password", passwd); |
System.out.println("url "+url); |
System.out.println("url "+url); |
if(url.indexOf("odbc")>=0) |
if (url.indexOf("fmpro") >= 0) |
{ |
{ |
// Connect to the database |
// Connect to the database |
connection = DriverManager.getConnection(url, prop); |
connection = DriverManager.getConnection(url, prop); |
System.out.println("odbc with properties inited"); |
System.out.println("odbc with properties inited"); |
} |
} else |
else |
|
connection = DriverManager.getConnection(url, user, passwd); |
connection = DriverManager.getConnection(url, user, passwd); |
connectionPool.put(url, new ConnectionPool(url, user, passwd, connection)); |
connectionPool.put(url, new ConnectionPool(url, user, passwd, connection)); |
|
|
Line 377 public class DBBean
|
Line 377 public class DBBean
|
* Returns the result for select * from table |
* Returns the result for select * from table |
* with maxHits = 500 default value |
* with maxHits = 500 default value |
*/ |
*/ |
public Vector[] getQueryData(String table) throws SQLException |
public Vector[] getQueryData(String table) throws SQLException, ParseException |
{ |
{ |
|
|
return getQueryData("SELECT * from " + quoteChar + table + quoteChar, maxHits); |
return getQueryData("SELECT * from " + quoteChar + table + quoteChar, maxHits); |
Line 457 public class DBBean
|
Line 457 public class DBBean
|
* Returns the result of the query |
* Returns the result of the query |
* or an Vector array of Vectors containing error messages |
* or an Vector array of Vectors containing error messages |
*/ |
*/ |
public Vector[] getQueryData(String query, int maxHits) throws SQLException |
public Vector[] getQueryData(String query, int maxHits) throws SQLException, ParseException |
{ |
{ |
long timeStart = System.currentTimeMillis(); |
long timeStart = System.currentTimeMillis(); |
ResultSet resultSet = null; |
ResultSet resultSet = null; |
Line 586 public class DBBean
|
Line 586 public class DBBean
|
// method returns a java.awt.Image object for FileMaker Pro |
// method returns a java.awt.Image object for FileMaker Pro |
// container fields |
// container fields |
|
|
|
try |
|
{ |
tableRow.addElement(resultSet.getDate(i)); |
tableRow.addElement(resultSet.getDate(i)); |
m_columnClasses.addElement(java.sql.Date.class); |
|
|
} catch (Exception e) |
|
{ |
|
// work around for parse bug in FM JDBC Driver |
|
// for dates of format dd-mm-yyyy |
|
String date = resultSet.getString(i); |
|
date = date.replace('-', '.'); |
|
java.text.DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, Locale.GERMAN); |
|
java.util.Date d = dateFormat.parse(date); |
|
// Calendar cal=Calendar.getInstance(Locale.GERMAN); |
|
// cal.setTime(d); |
|
// date=(cal.get(Calendar.YEAR))+"-"+(cal.get(Calendar.MONTH)+1)+"-"+cal.get(Calendar.DATE); |
|
tableRow.addElement(new java.sql.Date(d.getTime())); |
|
System.out.println("Date " + date); |
|
} |
} else if (metaData.getColumnTypeName(i) == "NUMBER") |
} else if (metaData.getColumnTypeName(i) == "NUMBER") |
{ |
{ |
// use the ResultSet.getObject method for retieving images |
// use the ResultSet.getObject method for retieving images |
Line 692 public class DBBean
|
Line 708 public class DBBean
|
|
|
if (!connection.isClosed()) |
if (!connection.isClosed()) |
stm = connection.createStatement(); |
stm = connection.createStatement(); |
else { |
else |
|
{ |
|
|
try |
try |
{ |
{ |
Line 707 public class DBBean
|
Line 723 public class DBBean
|
} |
} |
stm.setMaxRows(numberOfHits); |
stm.setMaxRows(numberOfHits); |
long time = System.currentTimeMillis(); |
long time = System.currentTimeMillis(); |
try { |
try |
|
{ |
stm.execute(query); |
stm.execute(query); |
long time2 = System.currentTimeMillis(); |
long time2 = System.currentTimeMillis(); |
|
|
Line 717 public class DBBean
|
Line 734 public class DBBean
|
result = stm.getResultSet(); |
result = stm.getResultSet(); |
// System.out.println(result+" "+stm.getUpdateCount()); |
// System.out.println(result+" "+stm.getUpdateCount()); |
metaData = result.getMetaData(); |
metaData = result.getMetaData(); |
} catch(Exception e) { |
} catch (Exception e) |
|
{ |
// TODO remove |
// TODO remove |
if(FM2SQL.fmInstance!=null) |
if(FM2SQL.fmInstance!=null) |
FM2SQL.showErrorDialog("Error caught!! \n Query was "+query+" \n","Debug Info"); |
FM2SQL.showErrorDialog("Error caught!! \n Query was "+query+" \n","Debug Info"); |
Line 1329 public class DBBean
|
Line 1347 public class DBBean
|
// container fields |
// container fields |
try |
try |
{ |
{ |
tableRow.addElement(new Double(resultSet.getDouble(i))); |
Double value =new Double(resultSet.getDouble(i)); |
|
|
|
|
|
// tableRow.addElement(new Double(resultSet.getDouble(i))); |
|
String tVal =value.toString(); |
|
tVal = tVal.substring(tVal.indexOf('.')+1); |
|
boolean checkMe = tVal.length()==1&&tVal.equals("0"); |
|
// System.out.println("check was"+checkMe+" "+tVal); |
|
if(checkMe) |
|
tableRow.addElement(new Integer(value.intValue())); |
|
else |
|
tableRow.addElement(value); |
|
|
// m_columnClasses.addElement(Integer.class); |
// m_columnClasses.addElement(Integer.class); |
|
|
} catch (Exception e) |
} catch (Exception e) |
Line 1362 public class DBBean
|
Line 1392 public class DBBean
|
byte[] b = null; |
byte[] b = null; |
if (metaData instanceof ResultSetMetaDataExt) |
if (metaData instanceof ResultSetMetaDataExt) |
b = resultSet.getBytes(i); |
b = resultSet.getBytes(i); |
|
/* if (b != null) |
|
{ |
|
java.io.ByteArrayInputStream stream = (java.io.ByteArrayInputStream) resultSet.getBinaryStream(i); |
|
// System.out.println(" stream "+resultSet.getBinaryStream(i)); |
|
byte[] c = new byte[stream.available()]; |
|
int length = stream.read(c, 0, c.length); |
|
int count = 0; |
|
b = new byte[c.length]; |
|
for (int n = 0; n < length; ++n) |
|
{ |
|
|
|
if (c[n] != 0) |
|
{ |
|
// System.out.println(c[n]+" "+(int)'?'+" "+(char)c[n]+" "+count+" "+b.length); |
|
b[count++] = c[n]; |
|
} |
|
} |
|
byte[] bCopy = new byte[count]; |
|
System.arraycopy(b, 0, bCopy, 0, count); |
|
b = bCopy; |
|
}*/ |
String utf8 = null; |
String utf8 = null; |
utf8 = (b == null) ? null : new String(b); |
utf8 = (b == null) ? null : new String(b); |
if (metaData instanceof ResultSetMetaDataExt) |
if (metaData instanceof ResultSetMetaDataExt) |
tableRow.addElement((b != null) ? new String(utf8.getBytes()) : null); |
{ |
else |
String rowElement = ""; |
|
if (b != null) |
|
{ |
|
rowElement = resultSet.getString(i); |
|
if (useNormanToUnicodeMapper) |
|
rowElement = Convert.normanToUnicode(rowElement); |
|
tableRow.addElement(rowElement); |
|
|
|
} else |
|
tableRow.addElement(null); |
|
} else |
{ |
{ |
if(url.toLowerCase().indexOf("odbc")>=0) |
if(url.toLowerCase().indexOf("odbc")>=0) |
{ |
{ |
Line 1382 public class DBBean
|
Line 1443 public class DBBean
|
} |
} |
} catch (Exception e) |
} catch (Exception e) |
{ |
{ |
System.out.println("Hey I Got an error" + e); |
System.out.println("Hey I got an error" + e); |
e.printStackTrace(); |
e.printStackTrace(); |
} |
} |
// m_columnClasses.addElement(java.lang.String.class); |
// m_columnClasses.addElement(java.lang.String.class); |
Line 1469 public class DBBean
|
Line 1530 public class DBBean
|
metaData = (this.result==null) ?null:this.result.getMetaData(); |
metaData = (this.result==null) ?null:this.result.getMetaData(); |
return t; |
return t; |
} |
} |
|
/** |
|
* @return |
|
*/ |
|
public boolean isUseNormanToUnicodeMapper() |
|
{ |
|
return useNormanToUnicodeMapper; |
|
} |
|
|
|
/** |
|
* @param b |
|
*/ |
|
public void setUseNormanToUnicodeMapper(boolean b) |
|
{ |
|
useNormanToUnicodeMapper = b; |
|
} |
|
|
} |
} |
|
|