List:Commits« Previous MessageNext Message »
From:tony.bedford Date:June 24 2010 3:00pm
Subject:svn commit - mysqldoc@docsrva: r21460 - trunk/sample-programs/connector-j-tutorials
View as plain text  
Author: tbedford
Date: 2010-06-24 17:00:26 +0200 (Thu, 24 Jun 2010)
New Revision: 21460

Log:
Call stored procedure

Added:
   trunk/sample-programs/connector-j-tutorials/CallStoredProcedure.java


Added: trunk/sample-programs/connector-j-tutorials/CallStoredProcedure.java
===================================================================
--- trunk/sample-programs/connector-j-tutorials/CallStoredProcedure.java	                        (rev 0)
+++ trunk/sample-programs/connector-j-tutorials/CallStoredProcedure.java	2010-06-24 15:00:26 UTC (rev 21460)
Changed blocks: 1, Lines Added: 41, Lines Deleted: 0; 1751 bytes

@@ -0,0 +1,41 @@
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.sql.CallableStatement;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+
+public class CallStoredProcedure {
+
+    public static void main(String[] args) {
+      
+        Connection conn   = null;
+    
+        try {
+            Class.forName("com.mysql.jdbc.Driver").newInstance();
+            String url = "jdbc:mysql://localhost/inventory";
+            conn = DriverManager.getConnection(url, "root", "");
+
+            CallableStatement cs = conn.prepareCall("{call ShowSuppliers}");
+            ResultSet rs = cs.executeQuery();
+
+            int supplier_id;
+            String supplier_name;
+            while (rs.next()) {
+                supplier_id = rs.getInt("supplier_id");
+                supplier_name = rs.getString("supplier_name");
+                System.out.println(supplier_id+" "+supplier_name);
+            }
+
+            
+        } catch (SQLException ex) {
+            System.out.println("SQLException: " + ex.getMessage());
+            System.out.println("SQLState: " + ex.getSQLState());
+            System.out.println("VendorError: " + ex.getErrorCode());
+        } catch (Exception e) {
+            System.out.println("Exception: " + e.getMessage());
+        }
+        
+    } // end main
+}
\ No newline at end of file


Thread
svn commit - mysqldoc@docsrva: r21460 - trunk/sample-programs/connector-j-tutorialstony.bedford24 Jun