1 24 47 48 package org.objectweb.cjdbc.console.text.commands.sqlconsole; 49 50 import java.io.IOException ; 51 import java.sql.CallableStatement ; 52 import java.sql.Connection ; 53 import java.sql.ResultSet ; 54 55 import org.objectweb.cjdbc.common.i18n.ConsoleTranslate; 56 import org.objectweb.cjdbc.console.text.ConsoleException; 57 import org.objectweb.cjdbc.console.text.commands.ConsoleCommand; 58 import org.objectweb.cjdbc.console.text.formatter.ResultSetFormatter; 59 import org.objectweb.cjdbc.console.text.module.VirtualDatabaseConsole; 60 61 66 public class CallStoredProcedure extends ConsoleCommand 67 { 68 69 74 public CallStoredProcedure(VirtualDatabaseConsole module) 75 { 76 super(module); 77 } 78 79 82 public void parse(String commandText) throws IOException , ConsoleException 83 { 84 callStoredProcedure(getCommandName() + " " + commandText); 85 } 86 87 90 public String getCommandName() 91 { 92 return "{call"; 93 } 94 95 98 public String getCommandParameters() 99 { 100 return ConsoleTranslate.get("sql.command.call.stored.procedure.params"); 101 } 102 103 106 public String getCommandDescription() 107 { 108 return ConsoleTranslate 109 .get("sql.command.call.stored.procedure.description"); 110 } 111 112 117 private synchronized void callStoredProcedure(String proc) 118 { 119 Connection connection = ((VirtualDatabaseConsole) module).getConnection(); 120 int fetchsize = ((VirtualDatabaseConsole) module).getFetchsize(); 121 CallableStatement cs = null; 122 try 123 { 124 cs = connection.prepareCall(proc); 125 cs.setQueryTimeout(((VirtualDatabaseConsole) module).getTimeout()); 126 127 long start = System.currentTimeMillis(); 128 long end; 129 ResultSet rs = cs.executeQuery(); 130 end = System.currentTimeMillis(); 131 ResultSetFormatter.formatAndDisplay(rs, fetchsize, console); 132 console.println(ConsoleTranslate.get("sql.display.query.time", 133 new Long []{new Long ((end - start) / 1000), 134 new Long ((end - start) % 1000)})); 135 } 136 catch (Exception e) 137 { 138 console.printError(ConsoleTranslate.get( 139 "sql.command.call.stored.procedure.failed", e), e); 140 } 141 finally 142 { 143 try 144 { 145 cs.close(); 146 } 147 catch (Exception ignore) 148 { 149 } 150 } 151 } 152 } | Popular Tags |