У меня возникла еще одна проблемма. Не могу создать подключение под MS SQL server. Видемо я чего то не допонял. ниже приведен код. Помогите кто чем может,мб даже своим рабочим кодом.
Код | package logic;
import com.microsoft.jdbcx.sqlserver.SQLServerDataSource; import java.sql.*;
import javax.sql.*;
public class MSFirstTry { private final static String myDriverString = "com.microsoft.jdbc.sqlserver.SQLServerDriver"; // String driverName = "com.jnetdirect.jsql.JSQLDriver"; // NetDirect JDBC driver
public static void main(String[] args) { System.setProperty("jdbc.drivers", myDriverString); // or the same // try { // Class.forName(myDriverString); // } catch (ClassNotFoundException e) { // e.printStackTrace(); // }
// getting driver properties // try { // String url = "jdbc:sqlserver:SQLServerDriver"; // Driver driver = DriverManager.getDriver(url); // // // Get available properties // DriverPropertyInfo[] info = driver.getPropertyInfo(url, null); // for (int i=0; i<info.length; i++) { // // Get name of property // String name = info[i].name; // // // Is property value required? // boolean isRequired = info[i].required; // // // Get current value // String value = info[i].value; // // // Get description of property // String desc = info[i].description; // // // Get possible choices for property; if null, value can be any string // String[] choices = info[i].choices; // System.out.println("name: " + name); // System.out.println("isRequied: " + isRequired); // System.out.println("value: " + value); // System.out.println("desc: " + desc); // System.out.print("choices: "); // if (choices == null) { // System.out.println("any"); // } else { // for (int j = 0; j < choices.length; ++j) { // System.out.print(choices[j] + ", "); // } // System.out.println(); // } // System.out.println(); // } // } catch (SQLException e) { // } Connection connection = null; try { String serverName = "127.0.0.1"; String portNumber = "1433"; String mydatabase = serverName + ":" + portNumber; String url = "jdbc:JSQLConnect://" + mydatabase; // a JDBC url // String url = "jdbc:sqlserver:SQLServerDriver"; String username = "username"; String password = "password"; // Create a connection to the database connection = DriverManager.getConnection(url, username, password); } catch (SQLException e) { // Could not connect to the database System.out.println("Failed to connect: " + e.getMessage()); } } }
|
|