locked
Connect to a SQL Server with JDBC RRS feed

  • Question

  • Hi!

    I have to do a program to connect to a SQL Server with JDBC, and I have two question

    1-      Can I connect to SQL Server with JDBC o with this code??

     SqlConnection con = new SqlConnection();

    con.ConnectionString = ("Data source=...; Initial Catalog=...; User Id=...; Password=..");

    con.Open();

    Can I only connect one way to the SQL server or can I choose how to connect?

    2-      I have this program

    String userName = "username";

    String password = "password";

    String url = "jdbc:sqlserver://MYPC\\SQLEXPRESS;databaseName=MYDB";

    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

    Connection conn = DriverManager.getConnection(url, userName, password);

    And I have an Error with Class.forName, because my Visual c# doesn´t recognize, What library have to add it to work?

    And another question, I am using Windows XP and Microsoft Visual C # 2010, need some special Instruction or library to connect to SQL Server?

    Thanks for all!

    Tuesday, July 7, 2015 8:30 AM

Answers

All replies

  • Hi, 

    the first code is C# but don't use JDBC with C# for connect with Sql Server. Try this : 

    C# with SQL Server

     the last  code is Java maybe forum the Java help you. See the link below :

    Java with Sql Server JDBC

    Java with Sql Server JDBC

     


    • Edited by Daniel Brito br Tuesday, July 7, 2015 11:18 AM
    • Proposed as answer by Kristin Xie Wednesday, July 8, 2015 7:19 AM
    • Marked as answer by Kristin Xie Wednesday, July 15, 2015 9:09 AM
    Tuesday, July 7, 2015 11:11 AM
  • These forums are for MS products.  Please post questions related to JDBC and Java in the Oracle forums as they are responsible for these technologies.
    • Proposed as answer by Kristin Xie Wednesday, July 8, 2015 7:16 AM
    • Unproposed as answer by Kristin Xie Wednesday, July 8, 2015 7:19 AM
    Tuesday, July 7, 2015 5:55 PM