Source Code Cross Referenced for JDBC3Test.java in  » Database-JDBC-Connection-Pool » jTDS » net » sourceforge » jtds » test » 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 JDBC Connection Pool » jTDS » net.sourceforge.jtds.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.sourceforge.jtds.test;
002:
003:        import java.sql.Statement;
004:        import java.sql.ResultSet;
005:        import java.sql.SQLException;
006:        import java.sql.PreparedStatement;
007:        import java.sql.ParameterMetaData;
008:        import java.sql.Types;
009:        import java.math.BigDecimal;
010:
011:        /**
012:         * Test for miscellaneous JDBC 3.0 features.
013:         *
014:         * @version $Id: JDBC3Test.java,v 1.3 2005/07/04 11:31:09 alin_sinpalean Exp $
015:         */
016:        public class JDBC3Test extends TestBase {
017:            public JDBC3Test(String name) {
018:                super (name);
019:            }
020:
021:            /**
022:             * Test return of multiple open result sets from one execute.
023:             */
024:            public void testMultipleResults() throws Exception {
025:                Statement stmt = con.createStatement(
026:                        ResultSet.TYPE_SCROLL_INSENSITIVE,
027:                        ResultSet.CONCUR_READ_ONLY);
028:                //
029:                // Create 4 test tables
030:                //
031:                for (int rs = 1; rs <= 4; rs++) {
032:                    stmt.execute("CREATE TABLE #TESTRS" + rs
033:                            + " (id int, data varchar(255))");
034:                    for (int row = 1; row <= 10; row++) {
035:                        assertEquals(1, stmt
036:                                .executeUpdate("INSERT INTO #TESTRS" + rs
037:                                        + " VALUES(" + row + ", 'TABLE " + rs
038:                                        + " ROW " + row + "')"));
039:                    }
040:                }
041:
042:                assertTrue(stmt.execute("SELECT * FROM #TESTRS1\r\n"
043:                        + "SELECT * FROM #TESTRS2\r\n"
044:                        + "SELECT * FROM #TESTRS3\r\n"
045:                        + "SELECT * FROM #TESTRS4\r\n"));
046:                ResultSet rs = stmt.getResultSet();
047:                assertTrue(rs.next());
048:                assertEquals("TABLE 1 ROW 1", rs.getString(2));
049:                // Get RS 2 keeping RS 1 open
050:                assertTrue(stmt.getMoreResults(Statement.KEEP_CURRENT_RESULT));
051:                ResultSet rs2 = stmt.getResultSet();
052:                assertTrue(rs2.next());
053:                assertEquals("TABLE 2 ROW 1", rs2.getString(2));
054:                // Check RS 1 still open and on row 1
055:                assertEquals("TABLE 1 ROW 1", rs.getString(2));
056:                // Read a cached row from RS 1
057:                assertTrue(rs.next());
058:                assertEquals("TABLE 1 ROW 2", rs.getString(2));
059:                // Close RS 2 but keep RS 1 open and get RS 3
060:                assertTrue(stmt.getMoreResults(Statement.CLOSE_CURRENT_RESULT));
061:                ResultSet rs3 = stmt.getResultSet();
062:                assertTrue(rs3.next());
063:                assertEquals("TABLE 3 ROW 1", rs3.getString(2));
064:                // Check RS 2 is closed
065:                try {
066:                    assertEquals("TABLE 2 ROW 1", rs2.getString(2));
067:                    fail("Expected RS 2 to be closed!");
068:                } catch (SQLException e) {
069:                    // Ignore
070:                }
071:                // Check RS 1 is still open
072:                assertEquals("TABLE 1 ROW 2", rs.getString(2));
073:                // Close all result sets and get RS 4
074:                assertTrue(stmt.getMoreResults(Statement.CLOSE_ALL_RESULTS));
075:                ResultSet rs4 = stmt.getResultSet();
076:                assertTrue(rs4.next());
077:                assertEquals("TABLE 4 ROW 1", rs4.getString(2));
078:                // check RS 1 is now closed as well
079:                try {
080:                    assertEquals("TABLE 1 ROW 2", rs.getString(2));
081:                    fail("Expected RS 1 to be closed!");
082:                } catch (SQLException e) {
083:                    // Ignore
084:                }
085:                assertFalse(stmt.getMoreResults());
086:                stmt.close();
087:            }
088:
089:            /**
090:             * Test closing a <code>ResultSet</code> when it's out of scope.
091:             * <p/>
092:             * If a finalize() method which tries to call close() is added to
093:             * JtdsResultSet the next() calls will be executed concurrently with any
094:             * other result processing, with no synchronization whatsoever.
095:             */
096:            public void testSocketConcurrency5() throws Exception {
097:                Statement stmt = con.createStatement();
098:                assertTrue(stmt.execute("SELECT 1 SELECT 2, 3"));
099:                ResultSet rs = stmt.getResultSet();
100:                assertTrue(stmt.getMoreResults(Statement.KEEP_CURRENT_RESULT));
101:                ResultSet rs2 = stmt.getResultSet();
102:
103:                assertTrue(rs.next());
104:                assertEquals(1, rs.getInt(1));
105:                assertFalse(rs.next());
106:                rs.close();
107:
108:                assertTrue(rs2.next());
109:                assertEquals(2, rs2.getInt(1));
110:                assertEquals(3, rs2.getInt(2));
111:                assertFalse(rs2.next());
112:                rs2.close();
113:
114:                stmt.close();
115:            }
116:
117:            /**
118:             * Test for bug [1222205] getParameterMetaData returns not implemented.
119:             */
120:            public void testGetParamMetaData() throws SQLException {
121:                PreparedStatement pstmt = con.prepareStatement("SELECT ?,?,?");
122:                pstmt.setString(1, "TEST");
123:                pstmt.setBigDecimal(2, new BigDecimal("123.45"));
124:                pstmt.setBoolean(3, true);
125:
126:                ParameterMetaData pmd = pstmt.getParameterMetaData();
127:                assertEquals(3, pmd.getParameterCount());
128:                assertEquals(Types.VARCHAR, pmd.getParameterType(1));
129:                assertEquals("java.lang.String", pmd.getParameterClassName(1));
130:                assertEquals(2, pmd.getScale(2));
131:                assertEquals(38, pmd.getPrecision(2));
132:                assertEquals(ParameterMetaData.parameterModeIn, pmd
133:                        .getParameterMode(3));
134:
135:                pstmt.close();
136:            }
137:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.