Java Doc for JdbcUtilities.java in  » Database-Client » iSQL-Viewer » org » isqlviewer » sql » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database Client » iSQL Viewer » org.isqlviewer.sql 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.isqlviewer.sql.JdbcUtilities

JdbcUtilities
final public class JdbcUtilities (Code)
Utility class for dealing with JDBC oriented tasks.

None of the methods that deal with ResultSets will actually close the ResultSet when completed, a call to the method first is called before and after each method is finished executing the defined function.

A small note about methods that use a the ResultSetViewer object as a parameter to the method is that if the ResultSetViewer is null and an SQLException occurs an attempt will be made to add the respecting exception as a warning to the given ResultSet object. So it recommended that if you want to know if an SQLException occured without using the ResultSetViewer check for warnings on the ResultSet after method invocation.
author:
   Markus A. Kobold <mkobold at sprintpcs dot com>





Method Summary
public static  voidconfigurePreparedStatement(PreparedStatement ps, Object[] data, int[] type, boolean convert)
     Helper method to the other configurePreparedStatement method.
public static  voidconfigurePreparedStatement(PreparedStatement ps, int index, Object value, int type, boolean convert)
     Helper method set data parameters of a PreparedStatement.

This method does make the assumption that the given object is of the correct type as this method will simply cast the object to the appropriate class based on the given SQL-Type.

public static  ObjectconvertValue(Object data, int type, Format fmt)
     Attempts to convert Object to it's standard type.

This method does make a fair attempt at conversion however it obviously can't convert everything.

public static synchronized  Map<String, Object>extractMetadata(DatabaseMetaData dmd)
    
public static  StringgeneratePreparedInsertRequest(String Table, String[] Columns)
     Helper method to assist with creating insert commands for prepared statements.

This will create an SQL statement in the following format.

public static  StringgeneratePreparedUpdateRequest(String Table, String[] Columns, String whereClause)
     Helper method to assist with creating update commands for prepared statements.

This will create an SQL statement in the following format.

public static  HashMap<String, Integer>getNativeTypeMap(DatabaseMetaData metaData)
    
public static  String[]getSQLTypes(boolean sorted)
     Returns a list of Strings of valid Java SQL types.

This method reflects through { java.sql.Types } object to get the names of all the fields in that object and returns them as an array.
Parameters:
  sorted - determines to sort the list or not.

public static  intgetTypeforName(String name)
     Refelcts to get SQL Type constant by name.
public static  StringgetTypeforValue(int type)
     Reverse lookup of a type name based on the constant.

This will iterate through the declared fields of the Types.class and once the correct field int value match the given type it will return the name of the field.
See Also:   JdbcUtilities.getTypeforName(String)
See Also:   Types
Parameters:
  type - to get Field name for.

public static  ObjectgetValueForType(ResultSet set, int type, int idx)
    
public static  booleanisBooleanType(int type)
     Helper method for determining if a given type is one of the Boolean SQL types.
public static  booleanisDateType(int type)
     Helper method for determining if a given type is one of the date SQL types.
public static  booleanisNumberType(int type)
     Helper method for determining if a given type is one of the numerical SQL types.
public static  booleanisStringType(int type)
     Helper method for determining if a given type is one of the String SQL types.
public static  booleanisUpdatable(ResultSet rs)
     Checks if the ResultSet is deemed updatable.

Basically if the ResultSet has the UPDATABLE concurrency and is not of the FORWARD_ONLY type this method will return true, IF the driver decides to throw exception when attempting to query this information this method will always return false.
See Also:   ResultSet.getConcurrency
See Also:   ResultSet.getType
Parameters:
  rs - to check for updatability.




Method Detail
configurePreparedStatement
public static void configurePreparedStatement(PreparedStatement ps, Object[] data, int[] type, boolean convert) throws SQLException(Code)
Helper method to the other configurePreparedStatement method.

This method consists of a simple for loop that calls the other configurePreparedStatement method.
See Also:   JdbcUtilities.configurePreparedStatement(PreparedStatement,int,Object,int,boolean)
Parameters:
  ps - PreparedStatement to configure.
Parameters:
  data - objects to set in the statement
Parameters:
  type - SQL-Types for each of the object.
throws:
  SQLException - if error occurs setting the objects in the prepared statement.
throws:
  NullPointerException - if data or type is null
throws:
  IllegalArgumentException - if the data.length != type.length




configurePreparedStatement
public static void configurePreparedStatement(PreparedStatement ps, int index, Object value, int type, boolean convert) throws SQLException(Code)
Helper method set data parameters of a PreparedStatement.

This method does make the assumption that the given object is of the correct type as this method will simply cast the object to the appropriate class based on the given SQL-Type. The logic as to what type should be what object is detailed in the convert method, as it is recommend to call convert before this method as the successful execution of convert will most likely ensure success of this method.

If the given value is null setNull(int,int) will be called on the statement and return immediately.
See Also:   JdbcUtilities.convertValue(Object,int,Format)
Parameters:
  index - of the given parameter in the statement (index >= 1)
Parameters:
  ps - PreparedStatement to configure.
Parameters:
  type - for the given data object.
throws:
  SQLException - if error occurs setting data.




convertValue
public static Object convertValue(Object data, int type, Format fmt) throws ParseException, IOException(Code)
Attempts to convert Object to it's standard type.

This method does make a fair attempt at conversion however it obviously can't convert everything. This method is mainly to address working with the configurePreparedStatements as those method make the assumptions that the objects are of type and simply casts them when appropriate.

Here is a rundown of what SQL Types goto what types. If the type is not listed here then object passed in will be passed back.

Types :

Anything not on the above list will not be converted to anything.
See Also:   Types
See Also:   JdbcUtilities.configurePreparedStatement(PreparedStatement,int,Object,int,boolean)
Parameters:
  data - to convert
Parameters:
  type - SQL type to convert to.
Parameters:
  fmt - object to use if parsing the data is required. converted object.
throws:
  ParseException - if using the format object parsing exception occurs.



extractMetadata
public static synchronized Map<String, Object> extractMetadata(DatabaseMetaData dmd)(Code)



generatePreparedInsertRequest
public static String generatePreparedInsertRequest(String Table, String[] Columns)(Code)
Helper method to assist with creating insert commands for prepared statements.

This will create an SQL statement in the following format.
INSERT INTO {Table} ({Colums[0],},.., {Columns[n]}) VALUES(?,..,?)
This method will return null if an exception occurs.
Parameters:
  Table - Name of table you wish to insert into.
Parameters:
  Columns - List of column names to declare values for. Generated SQL statement for use with creating prepared statements.




generatePreparedUpdateRequest
public static String generatePreparedUpdateRequest(String Table, String[] Columns, String whereClause)(Code)
Helper method to assist with creating update commands for prepared statements.

This will create an SQL statement in the following format.
UPDATE {Table} SET {Colums[0]=?,},.., {Columns[n]=?} WHERE {whereClause}
This method will return null if an exception occurs.
Parameters:
  Table - Name of table you wish to update.
Parameters:
  Columns - List of column names to update.
Parameters:
  whereClause - Standard SQL where clause for this update. Generated SQL statement for use with creating prepared statements.




getNativeTypeMap
public static HashMap<String, Integer> getNativeTypeMap(DatabaseMetaData metaData)(Code)



getSQLTypes
public static String[] getSQLTypes(boolean sorted)(Code)
Returns a list of Strings of valid Java SQL types.

This method reflects through { java.sql.Types } object to get the names of all the fields in that object and returns them as an array.
Parameters:
  sorted - determines to sort the list or not. String[] list of Types fields by name.




getTypeforName
public static int getTypeforName(String name)(Code)
Refelcts to get SQL Type constant by name.

Simple reflection utility to get the proper constant for the Type name.
See Also:   Types
See Also:   JdbcUtilities.getTypeforValue(int)
Parameters:
  name - valid field name in Types int representing the proper constant.




getTypeforValue
public static String getTypeforValue(int type)(Code)
Reverse lookup of a type name based on the constant.

This will iterate through the declared fields of the Types.class and once the correct field int value match the given type it will return the name of the field.
See Also:   JdbcUtilities.getTypeforName(String)
See Also:   Types
Parameters:
  type - to get Field name for. name of the field of Types.class based on the given constant.




getValueForType
public static Object getValueForType(ResultSet set, int type, int idx) throws SQLException(Code)



isBooleanType
public static boolean isBooleanType(int type)(Code)
Helper method for determining if a given type is one of the Boolean SQL types.

If the type equals BIT, BOOLEAN then this will return true otherwise false.
See Also:   Types
Parameters:
  type - SQL-Type to check true if the given type represents boolean objects




isDateType
public static boolean isDateType(int type)(Code)
Helper method for determining if a given type is one of the date SQL types.

If the type equals DATE,TIME,TIMESTAMP then this will return true otherwise false.
See Also:   Types
Parameters:
  type - SQL-Type to check true if the given type represents Date objects




isNumberType
public static boolean isNumberType(int type)(Code)
Helper method for determining if a given type is one of the numerical SQL types.

If the type equals BIGINT,DECIMAL,DOUBLE,FLOAT,INTEGER,NUMERIC,REAL,SMALLINT, and TINYINT then this will return true otherwise false.
See Also:   Types
Parameters:
  type - SQL-Type to check true if the given type represents numerical objects




isStringType
public static boolean isStringType(int type)(Code)
Helper method for determining if a given type is one of the String SQL types.

If the type equals CHAR,VARCHAR,LONGVARCHAR then this will return true otherwise false.
See Also:   Types
Parameters:
  type - SQL-Type to check true if the given type represents String objects




isUpdatable
public static boolean isUpdatable(ResultSet rs)(Code)
Checks if the ResultSet is deemed updatable.

Basically if the ResultSet has the UPDATABLE concurrency and is not of the FORWARD_ONLY type this method will return true, IF the driver decides to throw exception when attempting to query this information this method will always return false.
See Also:   ResultSet.getConcurrency
See Also:   ResultSet.getType
Parameters:
  rs - to check for updatability. true if the ResultSet should support updates.




Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.