Warning: Trying to access array offset on value of type bool in /home/feltexco/public_html/felix/wp-content/plugins/google-maps-ready/modules/options/models/options.php on line 16

Warning: Trying to access array offset on value of type bool in /home/feltexco/public_html/felix/wp-content/plugins/google-maps-ready/modules/options/models/options.php on line 16

Warning: Trying to access array offset on value of type bool in /home/feltexco/public_html/felix/wp-content/plugins/google-maps-ready/modules/options/models/options.php on line 16

Warning: Cannot modify header information - headers already sent by (output started at /home/feltexco/public_html/felix/wp-content/plugins/google-maps-ready/modules/options/models/options.php:16) in /home/feltexco/public_html/felix/wp-includes/rest-api/class-wp-rest-server.php on line 1758

Warning: Cannot modify header information - headers already sent by (output started at /home/feltexco/public_html/felix/wp-content/plugins/google-maps-ready/modules/options/models/options.php:16) in /home/feltexco/public_html/felix/wp-includes/rest-api/class-wp-rest-server.php on line 1758

Warning: Cannot modify header information - headers already sent by (output started at /home/feltexco/public_html/felix/wp-content/plugins/google-maps-ready/modules/options/models/options.php:16) in /home/feltexco/public_html/felix/wp-includes/rest-api/class-wp-rest-server.php on line 1758

Warning: Cannot modify header information - headers already sent by (output started at /home/feltexco/public_html/felix/wp-content/plugins/google-maps-ready/modules/options/models/options.php:16) in /home/feltexco/public_html/felix/wp-includes/rest-api/class-wp-rest-server.php on line 1758

Warning: Cannot modify header information - headers already sent by (output started at /home/feltexco/public_html/felix/wp-content/plugins/google-maps-ready/modules/options/models/options.php:16) in /home/feltexco/public_html/felix/wp-includes/rest-api/class-wp-rest-server.php on line 1758

Warning: Cannot modify header information - headers already sent by (output started at /home/feltexco/public_html/felix/wp-content/plugins/google-maps-ready/modules/options/models/options.php:16) in /home/feltexco/public_html/felix/wp-includes/rest-api/class-wp-rest-server.php on line 1758

Warning: Cannot modify header information - headers already sent by (output started at /home/feltexco/public_html/felix/wp-content/plugins/google-maps-ready/modules/options/models/options.php:16) in /home/feltexco/public_html/felix/wp-includes/rest-api/class-wp-rest-server.php on line 1758

Warning: Cannot modify header information - headers already sent by (output started at /home/feltexco/public_html/felix/wp-content/plugins/google-maps-ready/modules/options/models/options.php:16) in /home/feltexco/public_html/felix/wp-includes/rest-api/class-wp-rest-server.php on line 1758
{"id":1628,"date":"2014-11-20T13:34:27","date_gmt":"2014-11-20T15:34:27","guid":{"rendered":"http:\/\/www.feltex.com.br\/felix\/?p=1628"},"modified":"2015-01-16T18:28:53","modified_gmt":"2015-01-16T20:28:53","slug":"chamando-stored-procedure","status":"publish","type":"post","link":"https:\/\/www.feltex.com.br\/felix\/chamando-stored-procedure\/","title":{"rendered":"Dica R\u00e1pida: Chamando Stored Procedure em Java"},"content":{"rendered":"

Dica R\u00e1pida: Chamando Stored Procedure em Java<\/H1><\/p>\n

Ol\u00e1 amigos hoje a dica \u00e9 Stored Procedure. Muitos sistemas possuem suas regras de neg\u00f3cio centralizadas no banco de dados e as Stored Procedure s\u00e3o os objetos que realizam as opera\u00e7\u00f5es de Inclus\u00e3o, altera\u00e7\u00e3o, exclus\u00e3o e at\u00e9 mesmo consulta no Banco de dados.
\n Por este motivo \u00e9 importante sabermos trabalhar com esses objetos em Java. <\/p>\n

\"Stored<\/p>\n

<\/p>\n

Aprenda como acessar o banco de dados MySQL aqui<\/a>. <\/p>\n

1. Estrutura de dados<\/H2><\/p>\n

Veja o script de cria\u00e7\u00e3o da tabela.<\/p>\n

\r\nCREATE TABLE tbaluno (\r\nmatricula INT NOT NULL ,\r\nnome VARCHAR(45) NULL ,\r\ntelefone VARCHAR(45) NULL ,\r\nemail VARCHAR(45) NULL ,\r\ndatacadastro DATETIME NULL,\r\nPRIMARY KEY (matricula));\r\n<\/pre>\n

Agora vejamos o script para gera\u00e7\u00e3o de massa de dados:<\/p>\n

\r\ninsert into tbaluno (matricula, nome, telefone, email, datacadastro) \r\nvalues (1, 'maria da silva','5555-9887','maria.silva@feltex.com.br', '2020-10-10');\r\n\r\ninsert into tbaluno (matricula, nome, telefone, email, datacadastro) \r\nvalues (2, 'Jose da silva','2223-3222','jose.silva@feltex.com.br', '2020-10-10');\r\n\r\ninsert into tbaluno (matricula, nome, telefone, email, datacadastro) \r\nvalues (3, 'Bruna silva','4412-2234','bruna.silva@feltex.com.br', '2020-10-10');\r\n<\/pre>\n

2. Cria\u00e7\u00e3o da stored procedure<\/H2><\/p>\n

Criaremos uma procedure que nos retorna o total de alunos existentes em nossa tabela de alunos.<\/p>\n

\r\n\r\nDELIMITER $$\r\nCREATE PROCEDURE Total_Alunos(OUT total INT)\r\nBEGIN\r\n\tSELECT COUNT(matricula) INTO total FROM tbAluno;\t\r\nEND $$\r\n\r\n<\/pre>\n

3. Chamada Java<\/H2><\/p>\n

Abaixo temos o c\u00f3digo Java que executa a procedure e exibe o retorno.<\/p>\n

\r\npackage br.com.feltex.jdbc.avancado;\r\n\r\nimport java.sql.CallableStatement;\r\nimport java.sql.Connection;\r\nimport java.sql.DriverManager;\r\n\r\npublic class ChamaProcedure {\r\n\r\n\tpublic static Connection getConexao() {\r\n\t\tConnection conexao = null;\r\n\t\tString usuario = \"root\";\r\n\t\tString senha = \"teco01\";\r\n\t\tString nomeBancoDados = \"bdacademicnet\";\r\n\r\n\t\ttry {\r\n\t\t\tconexao = DriverManager.getConnection(\r\n\t\t\t\t\t\"jdbc:mysql:\/\/localhost:3306\/\" + nomeBancoDados, usuario,\r\n\t\t\t\t\tsenha);\r\n\t\t} catch (Exception e) {\r\n\t\t\te.printStackTrace();\r\n\t\t}\r\n\t\treturn conexao;\r\n\t}\r\n\r\n\tpublic static void main(String[] args) {\r\n\r\n\t\tCallableStatement callableStatement = null;\r\n\t\tConnection con = null;\r\n\r\n\t\ttry {\r\n\t\t\t\/\/ Realiza a conex\u00e3o com o banco de dados\r\n\t\t\tcon = getConexao();\r\n\t\t\t\r\n\t\t\t\/\/Prepara a chamada para a procedure. Observe que h\u00e1 \"?\"\r\n\t\t\t\/\/ Que neste caso \u00e9 o par\u00e2metro de sa\u00edda.\r\n\t\t\tcallableStatement = con.prepareCall(\"{CALL Total_Alunos(?)}\");\r\n\t\t\t\r\n\t\t\t\/\/Informa o tipo de retorno\r\n\t\t\tcallableStatement.registerOutParameter(1, java.sql.Types.INTEGER);\r\n\t\t\t\t\t\t\r\n\t\t\t\/\/ Executa a Stored procedure\r\n\t\t\tcallableStatement.execute();\r\n\t\t\t\r\n\t\t\t\/\/ Faz a leitura do retorno\r\n\t\t\tInteger totalAlunos = callableStatement.getInt(1);\r\n\t\t\t\r\n\t\t\tSystem.out.println(\"Total alunos: \" + totalAlunos);\r\n\r\n\t\t} catch (Exception e) {\r\n\t\t\te.printStackTrace();\r\n\t\t}\r\n\t}\r\n}\r\n<\/pre>\n
\n

Por hoje \u00e9 s\u00f3 meus amigos e Vida que segue!<\/p>\n

Links relacionados<\/h3>\n

Instala\u00e7\u00e3o e Configura\u00e7\u00e3o do Banco de Dados MySQL<\/a><\/p>\n

Stored procedure MySQL<\/a><\/p>\n

Chamando uma Stored Procedure<\/a><\/p>\n

N\u00e3o se esque\u00e7a de curtir este post nas redes sociais. D\u00ea a sua contribui\u00e7\u00e3o social e ajude o autor:<\/H2><\/p>\n","protected":false},"excerpt":{"rendered":"

Dica R\u00e1pida: Chamando Stored Procedure em Java Ol\u00e1 amigos hoje a dica \u00e9 Stored Procedure. Muitos sistemas possuem suas regras de neg\u00f3cio centralizadas no banco de dados e as Stored Procedure s\u00e3o os objetos que realizam as opera\u00e7\u00f5es de Inclus\u00e3o, …<\/p>\n

Dica R\u00e1pida: Chamando Stored Procedure em Java<\/span> Read More »<\/a><\/p>\n

<\/p>\n","protected":false},"author":1,"featured_media":1812,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0},"categories":[5,1,6],"tags":[],"yoast_head":"\nDica R\u00e1pida: Chamando Stored Procedure em Java<\/title>\n<meta name=\"description\" content=\"Ol\u00e1 amigos hoje a dica \u00e9 Stored Procedure.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.feltex.com.br\/felix\/chamando-stored-procedure\/\" \/>\n<meta property=\"og:locale\" content=\"pt_BR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Dica R\u00e1pida: Chamando Stored Procedure em Java\" \/>\n<meta property=\"og:description\" content=\"Ol\u00e1 amigos hoje a dica \u00e9 Stored Procedure.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.feltex.com.br\/felix\/chamando-stored-procedure\/\" \/>\n<meta property=\"og:site_name\" content=\"Aprenda Java\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/feltex.br\" \/>\n<meta property=\"article:published_time\" content=\"2014-11-20T15:34:27+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2015-01-16T20:28:53+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.feltex.com.br\/felix\/wp-content\/uploads\/2014\/11\/Stored-Procedure.png\" \/>\n\t<meta property=\"og:image:width\" content=\"512\" \/>\n\t<meta property=\"og:image:height\" content=\"512\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"twitter:label1\" content=\"Escrito por\" \/>\n\t<meta name=\"twitter:data1\" content=\"Andr\u00e9 F\u00e9lix\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. tempo de leitura\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.feltex.com.br\/felix\/#website\",\"url\":\"https:\/\/www.feltex.com.br\/felix\/\",\"name\":\"Aprenda Java\",\"description\":\"Cursos de java, SQL e Engenharia de Software\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.feltex.com.br\/felix\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"pt-BR\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.feltex.com.br\/felix\/chamando-stored-procedure\/#primaryimage\",\"inLanguage\":\"pt-BR\",\"url\":\"https:\/\/www.feltex.com.br\/felix\/wp-content\/uploads\/2014\/11\/Stored-Procedure.png\",\"contentUrl\":\"https:\/\/www.feltex.com.br\/felix\/wp-content\/uploads\/2014\/11\/Stored-Procedure.png\",\"width\":512,\"height\":512},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.feltex.com.br\/felix\/chamando-stored-procedure\/#webpage\",\"url\":\"https:\/\/www.feltex.com.br\/felix\/chamando-stored-procedure\/\",\"name\":\"Dica R\\u00e1pida: Chamando Stored Procedure em Java\",\"isPartOf\":{\"@id\":\"https:\/\/www.feltex.com.br\/felix\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.feltex.com.br\/felix\/chamando-stored-procedure\/#primaryimage\"},\"datePublished\":\"2014-11-20T15:34:27+00:00\",\"dateModified\":\"2015-01-16T20:28:53+00:00\",\"author\":{\"@id\":\"https:\/\/www.feltex.com.br\/felix\/#\/schema\/person\/1e49f842c6254b4561b66ccf573c2069\"},\"description\":\"Ol\\u00e1 amigos hoje a dica \\u00e9 Stored Procedure.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.feltex.com.br\/felix\/chamando-stored-procedure\/#breadcrumb\"},\"inLanguage\":\"pt-BR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.feltex.com.br\/felix\/chamando-stored-procedure\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.feltex.com.br\/felix\/chamando-stored-procedure\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Dica R\\u00e1pida: Chamando Stored Procedure em Java\"}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.feltex.com.br\/felix\/#\/schema\/person\/1e49f842c6254b4561b66ccf573c2069\",\"name\":\"Andr\\u00e9 F\\u00e9lix\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.feltex.com.br\/felix\/#personlogo\",\"inLanguage\":\"pt-BR\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d2d9cc82cab40245e6f803982b1448e6?s=96&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d2d9cc82cab40245e6f803982b1448e6?s=96&r=g\",\"caption\":\"Andr\\u00e9 F\\u00e9lix\"},\"sameAs\":[\"http:\/\/www.feltex.com.br\"],\"url\":\"https:\/\/www.feltex.com.br\/felix\/author\/andre.felix\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Dica R\u00e1pida: Chamando Stored Procedure em Java","description":"Ol\u00e1 amigos hoje a dica \u00e9 Stored Procedure.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.feltex.com.br\/felix\/chamando-stored-procedure\/","og_locale":"pt_BR","og_type":"article","og_title":"Dica R\u00e1pida: Chamando Stored Procedure em Java","og_description":"Ol\u00e1 amigos hoje a dica \u00e9 Stored Procedure.","og_url":"https:\/\/www.feltex.com.br\/felix\/chamando-stored-procedure\/","og_site_name":"Aprenda Java","article_publisher":"https:\/\/www.facebook.com\/feltex.br","article_published_time":"2014-11-20T15:34:27+00:00","article_modified_time":"2015-01-16T20:28:53+00:00","og_image":[{"width":512,"height":512,"url":"https:\/\/www.feltex.com.br\/felix\/wp-content\/uploads\/2014\/11\/Stored-Procedure.png","type":"image\/png"}],"twitter_misc":{"Escrito por":"Andr\u00e9 F\u00e9lix","Est. tempo de leitura":"2 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"https:\/\/www.feltex.com.br\/felix\/#website","url":"https:\/\/www.feltex.com.br\/felix\/","name":"Aprenda Java","description":"Cursos de java, SQL e Engenharia de Software","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.feltex.com.br\/felix\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"pt-BR"},{"@type":"ImageObject","@id":"https:\/\/www.feltex.com.br\/felix\/chamando-stored-procedure\/#primaryimage","inLanguage":"pt-BR","url":"https:\/\/www.feltex.com.br\/felix\/wp-content\/uploads\/2014\/11\/Stored-Procedure.png","contentUrl":"https:\/\/www.feltex.com.br\/felix\/wp-content\/uploads\/2014\/11\/Stored-Procedure.png","width":512,"height":512},{"@type":"WebPage","@id":"https:\/\/www.feltex.com.br\/felix\/chamando-stored-procedure\/#webpage","url":"https:\/\/www.feltex.com.br\/felix\/chamando-stored-procedure\/","name":"Dica R\u00e1pida: Chamando Stored Procedure em Java","isPartOf":{"@id":"https:\/\/www.feltex.com.br\/felix\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.feltex.com.br\/felix\/chamando-stored-procedure\/#primaryimage"},"datePublished":"2014-11-20T15:34:27+00:00","dateModified":"2015-01-16T20:28:53+00:00","author":{"@id":"https:\/\/www.feltex.com.br\/felix\/#\/schema\/person\/1e49f842c6254b4561b66ccf573c2069"},"description":"Ol\u00e1 amigos hoje a dica \u00e9 Stored Procedure.","breadcrumb":{"@id":"https:\/\/www.feltex.com.br\/felix\/chamando-stored-procedure\/#breadcrumb"},"inLanguage":"pt-BR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.feltex.com.br\/felix\/chamando-stored-procedure\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.feltex.com.br\/felix\/chamando-stored-procedure\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Dica R\u00e1pida: Chamando Stored Procedure em Java"}]},{"@type":"Person","@id":"https:\/\/www.feltex.com.br\/felix\/#\/schema\/person\/1e49f842c6254b4561b66ccf573c2069","name":"Andr\u00e9 F\u00e9lix","image":{"@type":"ImageObject","@id":"https:\/\/www.feltex.com.br\/felix\/#personlogo","inLanguage":"pt-BR","url":"https:\/\/secure.gravatar.com\/avatar\/d2d9cc82cab40245e6f803982b1448e6?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d2d9cc82cab40245e6f803982b1448e6?s=96&r=g","caption":"Andr\u00e9 F\u00e9lix"},"sameAs":["http:\/\/www.feltex.com.br"],"url":"https:\/\/www.feltex.com.br\/felix\/author\/andre.felix\/"}]}},"_links":{"self":[{"href":"https:\/\/www.feltex.com.br\/felix\/wp-json\/wp\/v2\/posts\/1628"}],"collection":[{"href":"https:\/\/www.feltex.com.br\/felix\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.feltex.com.br\/felix\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.feltex.com.br\/felix\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.feltex.com.br\/felix\/wp-json\/wp\/v2\/comments?post=1628"}],"version-history":[{"count":10,"href":"https:\/\/www.feltex.com.br\/felix\/wp-json\/wp\/v2\/posts\/1628\/revisions"}],"predecessor-version":[{"id":1823,"href":"https:\/\/www.feltex.com.br\/felix\/wp-json\/wp\/v2\/posts\/1628\/revisions\/1823"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.feltex.com.br\/felix\/wp-json\/wp\/v2\/media\/1812"}],"wp:attachment":[{"href":"https:\/\/www.feltex.com.br\/felix\/wp-json\/wp\/v2\/media?parent=1628"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.feltex.com.br\/felix\/wp-json\/wp\/v2\/categories?post=1628"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.feltex.com.br\/felix\/wp-json\/wp\/v2\/tags?post=1628"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}