connect = DriverManager.getConnection("" + "jdbc:sqlserver://bc6hela9fr.database.windows.net:1433;" + "database=thaicreate-db;" + "user=thaicreate_user@bc6hela9fr;password=password@123;" + "encrypt=true;hostNameInCertificate=*.database.windows.net;" + "loginTimeout=30;");
package com.java.myapp; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.sql.Connection; import java.sql.DriverManager; public class MyClass { public static void main(String[] args) { Connection connect = null; Statement s = null; try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); connect = DriverManager.getConnection("" + "jdbc:sqlserver://bc6hela9fr.database.windows.net:1433;" + "database=thaicreate-db;" + "user=thaicreate_user@bc6hela9fr;password=password@123;" + "encrypt=true;hostNameInCertificate=*.database.windows.net;" + "loginTimeout=30;"); s = connect.createStatement(); String sql = "SELECT * FROM customer ORDER BY CustomerID ASC"; ResultSet rec = s.executeQuery(sql); while((rec!=null) && (rec.next())) { System.out.print(rec.getString("CustomerID")); System.out.print(" - "); System.out.print(rec.getString("Name")); System.out.print(" - "); System.out.print(rec.getString("Email")); System.out.print(" - "); System.out.print(rec.getString("CountryCode")); System.out.print(" - "); System.out.print(rec.getFloat("Budget")); System.out.print(" - "); System.out.print(rec.getFloat("Used")); System.out.println(""); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } try { s.close(); connect.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท