1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 package complex.connectivity; 24 25 import com.sun.star.beans.PropertyState; 26 import com.sun.star.beans.PropertyValue; 27 import com.sun.star.lang.XMultiServiceFactory; 28 import com.sun.star.sdbc.XResultSet; 29 import com.sun.star.sdbc.XClob; 30 import com.sun.star.sdbc.XDriverAccess; 31 import com.sun.star.sdbc.XParameters; 32 import com.sun.star.sdbc.XPreparedStatement; 33 import com.sun.star.sdbc.XResultSetMetaData; 34 import com.sun.star.sdbc.XResultSetMetaDataSupplier; 35 import com.sun.star.sdbc.XRow; 36 import com.sun.star.uno.UnoRuntime; 37 import complexlib.ComplexTestCase; 38 39 public class JdbcLongVarCharTest extends ComplexTestCase 40 { 41 getTestMethodNames()42 public String[] getTestMethodNames() 43 { 44 return new String[] 45 { 46 "testLongVarChar" 47 }; 48 } 49 50 @Override getTestObjectName()51 public String getTestObjectName() 52 { 53 return "LongVarCharTest"; 54 } 55 testLongVarChar()56 public void testLongVarChar() throws com.sun.star.uno.Exception, com.sun.star.beans.UnknownPropertyException 57 { 58 59 try 60 { 61 System.out.println("== Start testing =="); 62 63 String url = "jdbc:mysql://localhost:3306/mysql?user=root"; 64 //String url = "jdbc:ingres://localhost:II7/demodb;AUTO=multi"; 65 com.sun.star.sdbc.XConnection xConnection = null; 66 com.sun.star.beans.PropertyValue prop[] = new PropertyValue[1]; 67 prop[0] = new PropertyValue("JavaDriverClass", 0, "com.mysql.jdbc.Driver", PropertyState.DIRECT_VALUE); 68 //prop[0] = new PropertyValue("JavaDriverClass", 0, "com.ingres.jdbc.IngresDriver", PropertyState.DIRECT_VALUE); 69 70 // get the remote office component context 71 XMultiServiceFactory xServiceManager = (XMultiServiceFactory) param.getMSF(); 72 Object x = xServiceManager.createInstance("com.sun.star.sdbc.DriverManager"); 73 com.sun.star.sdbc.XDriverAccess xDriverAccess = (XDriverAccess) UnoRuntime.queryInterface(XDriverAccess.class, x); 74 com.sun.star.sdbc.XDriver xDriver = xDriverAccess.getDriverByURL(url); 75 xConnection = xDriver.connect(url, prop); 76 77 //Object prepStmnt = xConnection.prepareStatement("SELECT * FROM t1 WHERE t1.c1 = ?"); 78 Object prepStmnt = xConnection.prepareStatement("SELECT * FROM i90114 WHERE i90114.c1 = ?"); 79 ((XParameters) UnoRuntime.queryInterface(XParameters.class, prepStmnt)).clearParameters(); 80 ((XParameters) UnoRuntime.queryInterface(XParameters.class, prepStmnt)).setInt(1, 1); 81 XResultSet xResultSet = ((XPreparedStatement) prepStmnt).executeQuery(); 82 XRow xRow = (XRow) UnoRuntime.queryInterface(XRow.class, xResultSet); 83 84 XResultSetMetaDataSupplier xRsMetaSup = (XResultSetMetaDataSupplier) UnoRuntime.queryInterface(XResultSetMetaDataSupplier.class, xResultSet); 85 XResultSetMetaData xRsMetaData = xRsMetaSup.getMetaData(); 86 int nColumnCount = xRsMetaData.getColumnCount(); 87 88 System.out.println("== MetaData =="); 89 for (int i = 1; i <= nColumnCount; ++i) 90 { 91 System.out.println("Name: " + xRsMetaData.getColumnName(i) + " Type: " + 92 xRsMetaData.getColumnType(i)); 93 } 94 95 System.out.println("== Result =="); 96 while (xResultSet.next()) 97 { 98 String str = "not set"; 99 100 XClob xClob = null; 101 xClob = xRow.getClob(2); 102 if (xClob != null) 103 { 104 System.out.println("xClob != null"); 105 int len = (int) xClob.length(); 106 str = xClob.getSubString(1, len); 107 } 108 else 109 { 110 System.out.println("xClob == null"); 111 } 112 113 System.out.println("c1 (Int): " + xRow.getInt(1) + " c2 (String): " + xRow.getString(2) + " c3 (Clob): " + str); 114 } 115 116 xConnection.close(); 117 } 118 catch (java.lang.Exception e) 119 { 120 System.out.println("== Exception occured while testing =="); 121 e.printStackTrace(); 122 } finally 123 { 124 System.out.println("== End testing =="); 125 System.exit(0); 126 } 127 } 128 }