version 1.11, 2004/03/23 11:57:06
|
version 1.19, 2004/05/11 09:06:38
|
Line 15
|
Line 15
|
|
|
|
|
import java.sql.*; |
import java.sql.*; |
|
import java.text.DateFormat; |
import java.util.*; |
import java.util.*; |
|
|
import com.fmi.jdbc.*; |
import com.fmi.jdbc.*; |
|
|
/** |
/** |
Line 83 public class DBBean
|
Line 85 public class DBBean
|
DriverManager.registerDriver((Driver) Class.forName("org.postgresql.Driver").newInstance()); |
DriverManager.registerDriver((Driver) Class.forName("org.postgresql.Driver").newInstance()); |
DriverManager.registerDriver((Driver) Class.forName("com.mysql.jdbc.Driver").newInstance()); |
DriverManager.registerDriver((Driver) Class.forName("com.mysql.jdbc.Driver").newInstance()); |
DriverManager.registerDriver((Driver) Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance()); |
DriverManager.registerDriver((Driver) Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance()); |
|
DriverManager.registerDriver((Driver) Class.forName("acs.jdbc.Driver").newInstance()); |
|
|
// wait a maximum of 10 seconds when attempting to establish a connection |
// wait a maximum of 10 seconds when attempting to establish a connection |
DriverManager.setLoginTimeout(10); |
DriverManager.setLoginTimeout(10); |
Line 150 public class DBBean
|
Line 153 public class DBBean
|
ConnectionPool conPool = (ConnectionPool) connectionPool.get(url); |
ConnectionPool conPool = (ConnectionPool) connectionPool.get(url); |
if (conPool == null) |
if (conPool == null) |
{ |
{ |
connection = DriverManager.getConnection(url, user, passwd); |
createConnection(); |
connectionPool.put(url, new ConnectionPool(url, user, passwd, connection)); |
|
} else |
} else |
{ |
{ |
if (!conPool.user.equals(user) || !conPool.passwd.equals(passwd)) |
if (!conPool.user.equals(user) || !conPool.passwd.equals(passwd)) |
Line 165 public class DBBean
|
Line 168 public class DBBean
|
if (connection.isClosed()) |
if (connection.isClosed()) |
{ |
{ |
System.out.println("Made new connection!!!"); |
System.out.println("Made new connection!!!"); |
connection = DriverManager.getConnection(conPool.url, conPool.user, conPool.passwd); |
createConnection(); |
|
|
|
// connection = DriverManager.getConnection(conPool.url, conPool.user, conPool.passwd); |
conPool.con = connection; |
conPool.con = connection; |
} |
} |
} |
} |
if (url != "" && connection == null) |
if (url != "" && connection == null) |
connection = DriverManager.getConnection(url, user, passwd); |
createConnection(); |
|
//connection = DriverManager.getConnection(url, user, passwd); |
dbMetaData = connection.getMetaData(); |
dbMetaData = connection.getMetaData(); |
quoteChar = dbMetaData.getIdentifierQuoteString(); |
quoteChar = dbMetaData.getIdentifierQuoteString(); |
if (quoteChar == null) |
if (quoteChar == null) |
Line 178 public class DBBean
|
Line 184 public class DBBean
|
|
|
return connection; |
return connection; |
} |
} |
|
private void createConnection() throws SQLException |
|
{ |
|
// setup the properties |
|
java.util.Properties prop = new java.util.Properties(); |
|
prop.put("charSet", "Cp1256"); |
|
prop.put("user", user); |
|
prop.put("password", passwd); |
|
System.out.println("url "+url); |
|
if(url.indexOf("odbc")>=0) |
|
{ |
|
// Connect to the database |
|
connection = DriverManager.getConnection(url, prop); |
|
System.out.println("odbc with properties inited"); |
|
} |
|
else |
|
connection = DriverManager.getConnection(url, user, passwd); |
|
connectionPool.put(url, new ConnectionPool(url, user, passwd, connection)); |
|
|
|
} |
/** |
/** |
* sets the connection of this DBBean to the database specified in the url |
* sets the connection of this DBBean to the database specified in the url |
* property |
* property |
Line 186 public class DBBean
|
Line 211 public class DBBean
|
{ |
{ |
this.url = url; |
this.url = url; |
if (url != "") |
if (url != "") |
connection = DriverManager.getConnection(url, user, passwd); |
//connection = DriverManager.getConnection(url, user, passwd); |
|
createConnection(); |
dbMetaData = connection.getMetaData(); |
dbMetaData = connection.getMetaData(); |
quoteChar = dbMetaData.getIdentifierQuoteString(); |
quoteChar = dbMetaData.getIdentifierQuoteString(); |
if (quoteChar == null) |
if (quoteChar == null) |
Line 202 public class DBBean
|
Line 228 public class DBBean
|
this.passwd = passwd; |
this.passwd = passwd; |
this.url = url; |
this.url = url; |
if (url != "") |
if (url != "") |
connection = DriverManager.getConnection(url, user, passwd); |
createConnection(); |
|
// connection = DriverManager.getConnection(url, user, passwd); |
dbMetaData = connection.getMetaData(); |
dbMetaData = connection.getMetaData(); |
quoteChar = dbMetaData.getIdentifierQuoteString(); |
quoteChar = dbMetaData.getIdentifierQuoteString(); |
if (quoteChar == null) |
if (quoteChar == null) |
Line 569 public class DBBean
|
Line 596 public class DBBean
|
// container fields |
// container fields |
try |
try |
{ |
{ |
tableRow.addElement(new Integer(resultSet.getInt(i))); |
tableRow.addElement(new Double(resultSet.getDouble(i))); |
m_columnClasses.addElement(Integer.class); |
m_columnClasses.addElement(Double.class); |
|
|
} catch (Exception e) |
} catch (Exception e) |
{ |
{ |
Line 588 public class DBBean
|
Line 615 public class DBBean
|
if (number.length() > 0) |
if (number.length() > 0) |
{ |
{ |
tableRow.addElement(null); |
tableRow.addElement(null); |
m_columnClasses.addElement(Integer.class); |
m_columnClasses.addElement(Double.class); |
} else |
} else |
tableRow.addElement(null); |
tableRow.addElement(null); |
} |
} |
Line 665 public class DBBean
|
Line 692 public class DBBean
|
|
|
if (!connection.isClosed()) |
if (!connection.isClosed()) |
stm = connection.createStatement(); |
stm = connection.createStatement(); |
|
else { |
|
|
|
|
|
try |
|
{ |
|
connection = getConnection(); |
|
stm= connection.createStatement(); |
|
} catch (Exception e) |
|
{ |
|
// TODO Auto-generated catch block |
|
e.printStackTrace(); |
|
} |
|
} |
stm.setMaxRows(numberOfHits); |
stm.setMaxRows(numberOfHits); |
long time = System.currentTimeMillis(); |
long time = System.currentTimeMillis(); |
|
try { |
stm.execute(query); |
stm.execute(query); |
long time2 = System.currentTimeMillis(); |
long time2 = System.currentTimeMillis(); |
|
|
Line 676 public class DBBean
|
Line 717 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) { |
|
// TODO remove |
|
if(FM2SQL.fmInstance!=null) |
|
FM2SQL.showErrorDialog("Error caught!! \n Query was "+query+" \n","Debug Info"); |
|
} |
|
|
return result; |
return result; |
} |
} |
/** |
/** |
Line 1255 public class DBBean
|
Line 1302 public class DBBean
|
// from FileMaker Pro container fields; the ResultSet.getObject |
// from FileMaker Pro container fields; the ResultSet.getObject |
// 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)); |
|
|
|
} 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); |
|
} |
// m_columnClasses.addElement(java.sql.Date.class); |
// m_columnClasses.addElement(java.sql.Date.class); |
} else if (metaData.getColumnTypeName(i) == "NUMBER") |
} else if (metaData.getColumnTypeName(i) == "NUMBER") |
{ |
{ |
Line 1266 public class DBBean
|
Line 1329 public class DBBean
|
// container fields |
// container fields |
try |
try |
{ |
{ |
tableRow.addElement(new Integer(resultSet.getInt(i))); |
tableRow.addElement(new Double(resultSet.getDouble(i))); |
// m_columnClasses.addElement(Integer.class); |
// m_columnClasses.addElement(Integer.class); |
|
|
} catch (Exception e) |
} catch (Exception e) |
Line 1305 public class DBBean
|
Line 1368 public class DBBean
|
tableRow.addElement((b != null) ? new String(utf8.getBytes()) : null); |
tableRow.addElement((b != null) ? new String(utf8.getBytes()) : null); |
else |
else |
{ |
{ |
|
if(url.toLowerCase().indexOf("odbc")>=0) |
|
{ |
|
byte[] val = resultSet.getBytes(i); |
|
for(int j=0;j<val.length;++j) |
|
System.out.println(Integer.toHexString(val[j])); |
|
tableRow.addElement((val==null) ? null:new String(val)); |
|
|
|
} else |
// byte[] val = resultSet.getBytes(i); |
// byte[] val = resultSet.getBytes(i); |
tableRow.add(resultSet.getString(i)); |
tableRow.add(resultSet.getString(i)); |
//tableRow.addElement((val==null) ? null:new String(val,"UTF-8")); |
//tableRow.addElement((val==null) ? null:new String(val,"UTF-8")); |