Results 1 to 2 of 2
  1. #1
    sabra is offline Member
    Join Date
    Jun 2010
    Posts
    6
    Rep Power
    0

    Default error in Connection

    import java.sql.*;

    public class DrugaProba {

    public static void main(String[] args) {

    // Create a variable for the connection string.
    String connectionUrl = "jdbc:sqlserver://localhost:1433;" +
    "databaseName=ProbaBaza;integratedSecurity=false;u ser=sa;password=javajdbc";

    // Declare the JDBC objects.
    Connection con = null;
    Statement stmt = null;
    ResultSet rs = null;

    try {

    // Establish the connection.
    // Create and execute an SQL statement that returns a
    // set of data and then display it.
    String SQL = "SELECT * FROM Nesto;";
    stmt = con.createStatement();
    rs = stmt.executeQuery(SQL);
    displayRow("PrezimeIme", rs);
    }

    // Handle any errors that may have occurred.
    catch (Exception e) {
    e.printStackTrace();
    }

    finally {
    if (rs != null) try { rs.close(); } catch(Exception e) {}
    if (stmt != null) try { stmt.close(); } catch(Exception e) {}
    if (con != null) try { con.close(); } catch(Exception e) {}
    }
    }

    private static void displayRow(String title, ResultSet rs) {
    try {
    System.out.println(title);
    while (rs.next()) {
    System.out.println(rs.getString("Prezime") + " , " + rs.getString("Ime"));
    }
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    }
    :eek:

  2. #2
    HerrK. is offline Member
    Join Date
    Jun 2010
    Location
    Berlin
    Posts
    22
    Rep Power
    0

    Default

    So what is your question? What exception to you get and what do you think this might be caused by? If you want someone to help you, start by using the code-tags and format your source.

    I guess you get some kind of NullPointer exception, while you do
    Java Code:
    stmt = con.createStatement();
    without ever setting con to anything but null.

Similar Threads

  1. Connection Error
    By meMalik in forum JavaServer Faces (JSF)
    Replies: 1
    Last Post: 02-22-2010, 07:13 PM
  2. Help me this error in JDBC-ODBC connection
    By lordelf in forum Java Servlet
    Replies: 3
    Last Post: 04-04-2009, 09:37 AM
  3. Connection reset error in FTP client
    By Waterbottle in forum Networking
    Replies: 0
    Last Post: 03-23-2009, 10:03 AM
  4. RAD - Error getting connection: Timeout.
    By ShoeNinja in forum Other IDEs
    Replies: 0
    Last Post: 09-09-2008, 06:25 PM
  5. error I/O connection
    By bbq in forum JDBC
    Replies: 1
    Last Post: 07-05-2007, 02:33 PM

Posting Permissions

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