{"id":76673,"date":"2025-04-03T20:06:37","date_gmt":"2025-04-03T20:06:37","guid":{"rendered":"http:\/\/bangla.sitestree.com\/?p=76673"},"modified":"2025-04-03T20:06:38","modified_gmt":"2025-04-03T20:06:38","slug":"connect-to-sql-server-from-java","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=76673","title":{"rendered":"Connect to Sql Server FROM JAVA"},"content":{"rendered":"\n<p><a href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/connect\/jdbc\/connection-url-sample?view=sql-server-ver16\">https:\/\/learn.microsoft.com\/en-us\/sql\/connect\/jdbc\/connection-url-sample?view=sql-server-ver16<\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.sql.Connection;\nimport java.sql.DriverManager;\nimport java.sql.ResultSet;\nimport java.sql.SQLException;\nimport java.sql.Statement;\n\npublic class ConnectURL {\n    public static void main(String&#91;] args) {\n\n<strong>        \/\/ Create a variable for the connection string.\n        String connectionUrl = \"jdbc:sqlserver:\/\/&lt;server>:&lt;port>;encrypt=true;databaseName=AdventureWorks;user=&lt;user>;password=&lt;password>\";\n\n        try (Connection con = DriverManager.getConnection(connectionUrl); Statement stmt = con.createStatement();) <\/strong>{\n            String SQL = \"SELECT TOP 10 * FROM Person.Contact\";\n            ResultSet rs = stmt.executeQuery(SQL);\n\n            \/\/ Iterate through the data in the result set and display it.\n            while (rs.next()) {\n                System.out.println(rs.getString(\"FirstName\") + \" \" + rs.getString(\"LastName\"));\n            }\n        }\n        \/\/ Handle any errors that may have occurred.\n        catch (SQLException e) {\n            e.printStackTrace();\n        }\n    }\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/learn.microsoft.com\/en-us\/sql\/connect\/jdbc\/connection-url-sample?view=sql-server-ver16<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-76673","post","type-post","status-publish","format-standard","hentry","category-root","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":10116,"url":"http:\/\/bangla.sitestree.com\/?p=10116","url_meta":{"origin":76673,"position":0},"title":"DBResults.java: Class to store completed results of a JDBC Query. Differs from a ResultSet in several ways","author":"","date":"August 5, 2015","format":false,"excerpt":"# DBResults.java\u00a0 Class to store completed results of a JDBC Query. Differs from a ResultSet in several ways: \u00a0\u00a0\u00a0 * ResultSet doesn?t necessarily have all the data; reconnection to database occurs as you ask for later rows. \u00a0\u00a0\u00a0 * This class stores results as strings, in arrays. \u00a0\u00a0\u00a0 * This\u2026","rel":"","context":"In &quot;Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8&quot;","block_context":{"text":"Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8","link":"http:\/\/bangla.sitestree.com\/?cat=1417"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10106,"url":"http:\/\/bangla.sitestree.com\/?p=10106","url_meta":{"origin":76673,"position":1},"title":"FruitTest.java: A class that connects to either an Oracle or a Sybase database and prints out the values of predetermined columns in the &#8220;fruits&#8221; table.","author":"","date":"August 2, 2015","format":false,"excerpt":"# FruitTest.java\u00a0 A class that connects to either an Oracle or a Sybase database and prints out the values of predetermined columns in the \"fruits\" table. package cwp; import java.sql.*; \/** A JDBC example that connects to either an Oracle or \u00a0*\u00a0 a Sybase database and prints out the values\u2026","rel":"","context":"In &quot;Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8&quot;","block_context":{"text":"Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8","link":"http:\/\/bangla.sitestree.com\/?cat=1417"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":7003,"url":"http:\/\/bangla.sitestree.com\/?p=7003","url_meta":{"origin":76673,"position":2},"title":"MongoDB Java","author":"Author-Check- Article-or-Video","date":"March 16, 2015","format":false,"excerpt":"Done By Raju(DU) MongoDB Java Installation \u09aa\u09a6\u09cd\u09a7\u09a4\u09bf\u0983 Java program \u098f MongoDB \u09ac\u09cd\u09af\u09be\u09ac\u09b9\u09be\u09b0 \u0995\u09b0\u09be\u09b0 \u09aa\u09c2\u09b0\u09cd\u09ac\u09c7 \u0986\u09ae\u09be\u09a6\u09c7\u09b0\u0995\u09c7 \u09a8\u09bf\u09b6\u09cd\u099a\u09bf\u09a4 \u0995\u09b0\u09a4\u09c7 \u09b9\u09ac\u09c7 \u09af\u09c7 MongoDB JDBC Driver \u098f\u09ac\u0982 Java \u0986\u09ae\u09be\u09a6\u09c7\u09b0 machine \u098f \u09aa\u09c2\u09b0\u09cd\u09ac\u09c7 \u09a5\u09c7\u0995\u09c7\u0987 \u09b0\u09df\u09c7\u099b\u09c7\u0964 \u0986\u09aa\u09a8\u09bf \u0986\u09b0\u0993 Java tutorial \u09a6\u09c7\u0996\u09a4\u09c7 \u09aa\u09be\u09b0\u09c7\u09a8 \u0986\u09aa\u09a8\u09be\u09b0 machine \u098f Java installation \u0995\u09b0\u09be\u09b0 \u099c\u09a8\u09cd\u09af\u0964 \u098f\u0996\u09a8 \u09a6\u09c7\u0996\u09ac\u09c7 \u0995\u09bf\u09ad\u09be\u09ac\u09c7 MongoDB JDBC driver \u099f\u09bf\u2026","rel":"","context":"In &quot;\u09ae\u0999\u09cd\u0997 \u09a1\u09bf \u09ac\u09bf \u0964 MongoDB&quot;","block_context":{"text":"\u09ae\u0999\u09cd\u0997 \u09a1\u09bf \u09ac\u09bf \u0964 MongoDB","link":"http:\/\/bangla.sitestree.com\/?cat=222"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":26830,"url":"http:\/\/bangla.sitestree.com\/?p=26830","url_meta":{"origin":76673,"position":3},"title":"DBResults.java: Class to store completed results of a JDBC Query. Differs from a ResultSet in several ways #Programming Code Examples #Java\/J2EE\/J2ME #JDBC","author":"Author-Check- Article-or-Video","date":"May 2, 2021","format":false,"excerpt":"# DBResults.java Class to store completed results of a JDBC Query. Differs from a ResultSet in several ways: * ResultSet doesn?t necessarily have all the data; reconnection to database occurs as you ask for later rows. * This class stores results as strings, in arrays. * This class includes DatabaseMetaData\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":26826,"url":"http:\/\/bangla.sitestree.com\/?p=26826","url_meta":{"origin":76673,"position":4},"title":"FruitCreation.java:  Creates a simple table named fruits in either an Oracle or a Sybase database. #Programming Code Examples #Java\/J2EE\/J2ME #JDBC","author":"Author-Check- Article-or-Video","date":"May 2, 2021","format":false,"excerpt":"FruitCreation.java Creates a simple table named fruits in either an Oracle or a Sybase database. ************************************** package cwp; import java.sql.*; \/** Creates a simple table named \"fruits\" in either * an Oracle or a Sybase database. * *\/ public class FruitCreation { public static void main(String[] args) { if (args.length\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":26822,"url":"http:\/\/bangla.sitestree.com\/?p=26822","url_meta":{"origin":76673,"position":5},"title":"FruitTest.java:  A class that connects to either an Oracle or a Sybase database and prints out the values of predetermined columns in the &quot;fruits&quot; table. #Programming Code Examples #Java\/J2EE\/J2ME #JDBC","author":"Author-Check- Article-or-Video","date":"May 2, 2021","format":false,"excerpt":"# FruitTest.java A class that connects to either an Oracle or a Sybase database and prints out the values of predetermined columns in the \"fruits\" table. package cwp; import java.sql.*; \/** A JDBC example that connects to either an Oracle or * a Sybase database and prints out the values\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/76673","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=76673"}],"version-history":[{"count":1,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/76673\/revisions"}],"predecessor-version":[{"id":76674,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/76673\/revisions\/76674"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=76673"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=76673"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=76673"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}