Results 1 to 2 of 2
Thread: error in Connection
- 06-12-2010, 08:32 AM #1
Member
- Join Date
- Jun 2010
- Posts
- 6
- Rep Power
- 0
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:
- 06-12-2010, 12:02 PM #2
Member
- Join Date
- Jun 2010
- Location
- Berlin
- Posts
- 22
- Rep Power
- 0
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
without ever setting con to anything but null.Java Code:stmt = con.createStatement();
Similar Threads
-
Connection Error
By meMalik in forum JavaServer Faces (JSF)Replies: 1Last Post: 02-22-2010, 06:13 PM -
Help me this error in JDBC-ODBC connection
By lordelf in forum Java ServletReplies: 3Last Post: 04-04-2009, 08:37 AM -
Connection reset error in FTP client
By Waterbottle in forum NetworkingReplies: 0Last Post: 03-23-2009, 09:03 AM -
RAD - Error getting connection: Timeout.
By ShoeNinja in forum Other IDEsReplies: 0Last Post: 09-09-2008, 05:25 PM -
error I/O connection
By bbq in forum JDBCReplies: 1Last Post: 07-05-2007, 01:33 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks