Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Other Java > Java Databases
|
Java Databases Discussion specific to working with Java Databases. For other Java topics, please see related Java forums. For database discussions not specific to Java, please see the Database category.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 12th, 2010, 09:23 AM
Authorized User
 
Join Date: Jul 2006
Posts: 73
Thanks: 11
Thanked 1 Time in 1 Post
Thumbs down Problem with Class.forName();

import java.sql.*;


publicclass JDBCConnectionExample {


/**

* @param args

*/

publicstaticvoid main(String[] args) {

// TODO Auto-generated method stub

// Create a variable for the connection string.

String connectionUrl = "jdbc:sqlserver://localhost:1433;" +

"databaseName=NovaBaza;integratedSecurity=false;us er=sa;password=javajdbc";


// Declare the JDBC objects.

Connection con = null;

Statement stmt = null;

ResultSet rs = null;


try {


// Establish the connection.

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

con = DriverManager.getConnection(connectionUrl);


// Create and execute an SQL statement that returns a

// set of data and then display it.

//String SQL = "SELECT * FROM BLOBTest;";

//stmt = con.createStatement();

//rs = stmt.executeQuery(SQL);

//displayRow("Ident", 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());

// }

} catch (Exception e) {

e.printStackTrace();

}

}

}
error
java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at JDBCConnectionExample.main(JDBCConnectionExample.java:22)





Similar Threads
Thread Thread Starter Forum Replies Last Post
class problem beetle_jaipur CSS Cascading Style Sheets 2 March 5th, 2009 03:34 AM
Problem in Globals class pedroabs BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 8 June 12th, 2008 01:11 PM
Problem with class.......help Pettman ASP.NET 2.0 Basics 2 March 1st, 2006 03:51 PM
problem with using WebRequest class in C# anilkumarbv General .NET 0 December 28th, 2004 02:23 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.