Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: SQLServer Hell

  1. #1
    Junior Member
    Join Date
    Sep 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy SQLServer Hell

    Hi, I'm new at java programming and wanted to do some first steps calling some data from a MS SQL server table (changing to mysql or any other db system is out of the question) and I'm using the jtds library, the connection is good, but can't get any data and I don't know why that is, please someone point me in the right direction

    Class.forName("net.sourceforge.jtds.jdbc.Driver");
    			Connection conn = DriverManager.getConnection("jdbc:jtds:sqlserver://192.168.0.1:1433/MyDB", "sa", "myPass");
    			Statement stt = conn.createStatement();
    			ResultSet rs = stt.executeQuery("select code from MyDB.dbo.table");
    			while (rs.next())
    			{
    				System.out.print(rs.getInt(0));
    			}
    			rs.close();
    			conn.close();

    I put a breakpoint in the while line but the rs seems to be empty, and it never goes inside the loop, the connection seems to be fine, i can connect from my macbook to the server and make queries, no problem there, I just can't explain what happens, I was wondering where can I see the error, I'm using Eclipse Helios.

    Thanks.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: SQLServer Hell

    You touched on this a bit, but I'll suggest you should verify the syntax in the SQL query (I presume you can copy and paste this query directly into some database interface and retrieve the appropriate information? - if the answer is yes I'd play with the syntax - for example remove the database name as this is redundant since you've already done so in your connection url). Also, make sure the username/password has the correct permission to the database.

  3. #3
    Junior Member
    Join Date
    Sep 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: SQLServer Hell

    Hi, thanks for the tips, but I've done all that already, I have a program called RazorSQL which connects with the same driver, and I pasted this code from a query I already did on that program. As I stated, the connection works ok so user and password are ok too.

    Any tips on how can I see a trace of the error if any? maybe that could point me on what is wrong

  4. #4
    Junior Member
    Join Date
    Sep 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: SQLServer Hell

    Hi, it seems I had problems with datatypes, I enclosed the code inside a try .. catch and caught the exception.

    Thank you.

Similar Threads

  1. Hell world :)
    By Kassino in forum Member Introductions
    Replies: 2
    Last Post: May 10th, 2010, 08:48 AM