Results 1 to 11 of 11
  1. #1
    sandeep43 is offline Member
    Join Date
    May 2011
    Posts
    97
    Rep Power
    0

    Question How to connect to any database without any JDBC driver?

    Hi All,

    How to connect to any database example mysql or oracle etc without any help from JDBC connection(drivers) using NetBeans. Can we develop/connect just using code for an ActionPerformed event on a button called "Test Connection"?

    Please help me out, i am stuck in middle of the application

    Thanks in advance

    Regards
    Sandeep

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,967
    Rep Power
    19

    Default

    You'd have to know the protocol that that particular database uses for incoming connections...
    That is, the sort of thing the JDBC driver does for you.

    So you'd need to know which db you were connecting to, and handle the connection appropriately (with db specific code). Which means you may as well have the correct drivers in the first place.

  3. #3
    hitesh is offline Member
    Join Date
    Jul 2010
    Posts
    28
    Rep Power
    0

    Default

    I dont think, you can do that without a JDBC driver. But with Netbeans and mysql you need not to worry about the JDBC driver. Because Netbeans automatically detect the mysql JDBC driver. You just need to select the driver from the drop down box at the time of creating the project(database application).

  4. #4
    sandeep43 is offline Member
    Join Date
    May 2011
    Posts
    97
    Rep Power
    0

    Default

    HI thanks for for reply.

    @hitesh: i want to be semaless access i.e not only mysql i have to develop even for oracle, sysbase etc

    now i am getting this error

    "The TCP/IP connection to the host 192.168.2.2, port 1433 has failed. Error: "Connection refused: connect. Verify the connection properties, check that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port, and that no firewall is blocking TCP connections to the port."."

    192.168.2.2 is my localhost name

    Please help me in solving this issue.

    Thanks in advance

    Regards
    Sandeep

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,967
    Rep Power
    19

    Default

    If you have to develop for all those then provide drivers for all those, and use something like Hibernate.

    As for your error, have you checked your SQL Server is setup to accept connections? If not, then you need to go and find the How To article over at MSDN.

  6. #6
    hitesh is offline Member
    Join Date
    Jul 2010
    Posts
    28
    Rep Power
    0

    Default

    check that sql server is running. If not play the server
    off the firewall of your machine ............then try again

  7. #7
    sandeep43 is offline Member
    Join Date
    May 2011
    Posts
    97
    Rep Power
    0

    Default

    Hi

    I have installed JDBC drivers also, once installed, it shld not be a huge prob to connect, but still i am facing probs in it

    My code is :

    try {
    Class.forName("com.microsoft.sqlserver.jdbc.SQLSer verDriver");
    String url = "jdbc:sqlserver://192.168.2.2:80;" + "databaseName=HR89DMO1;"+ "integratedSecurity=true;"+"user=UserName;password =P@ssw0rd";
    Connection con = DriverManager.getConnection(url);
    Statement stmt = con.createStatement();

    ResultSet rs;

    rs = stmt.executeQuery("SELECT EMPLID FROM PS_JOB where EMPLID='1042'");

    while ( rs.next() ) {
    String EMPLID = rs.getString("EMPLID");
    System.out.println(EMPLID);
    }
    con.close();
    } catch (Exception e) {
    System.err.println("Got an exception! ");
    System.err.println(e.getMessage());
    }

    Thanks in advance please help me


    Regards
    Sandeep

  8. #8
    sandeep43 is offline Member
    Join Date
    May 2011
    Posts
    97
    Rep Power
    0

    Default

    Error is
    The driver received an unexpected pre-login response. Verify the connection properties and check that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. This driver can be used only with SQL Server 2000 or later." for port Number:80

    If i change my port number to default i.e. 1433 Error is :

    The TCP/IP connection to the host 192.168.2.2, port 1433 has failed. Error: "Connection refused: connect. Verify the connection properties, check that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port, and that no firewall is blocking TCP connections to the port.".

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,967
    Rep Power
    19

    Default

    "accepting TCP/IP connections at the port"
    Have you checked the SQL Server installation to ensure that it is set up to accept connections?

    And please use code tags when posting code.

  10. #10
    sandeep43 is offline Member
    Join Date
    May 2011
    Posts
    97
    Rep Power
    0

    Default

    Hi Tolls,

    Thanks for ur reply and yea sure i ll use code tags in future to post code. :)

    yea it tells tats all, before that if u read closely it says Connection Refused and then it is saying to check all these connections, but all these connections are correct and properly working.

    Any thoughts please help me out


    Regards
    Sandeep

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,967
    Rep Power
    19

    Default

    You will get a connection refused if the SQL Server has not been setup up to accept TCP/IP connections.
    It will also do that if the port is configured as dynamic rather than static.
    If that isn't the case, then either there's a firewall blocking that port, or you've misspelt the server name.

    That's it...
    Last edited by Tolls; 05-20-2011 at 11:06 AM. Reason: typo

Similar Threads

  1. unable to connect remote database using jdbc
    By enggvijaysingh@gmail.com in forum Advanced Java
    Replies: 1
    Last Post: 12-16-2010, 12:16 PM
  2. how to connect to database using jdbc in servelets
    By sureshmca08 in forum Java Servlet
    Replies: 2
    Last Post: 05-28-2010, 09:06 AM
  3. Replies: 4
    Last Post: 02-04-2009, 03:19 PM
  4. connect JDBC to offline database
    By nancyhung in forum JDBC
    Replies: 1
    Last Post: 04-11-2008, 11:04 PM
  5. Using JDBC to connect to ORACLE database
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-10-2008, 11:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •