Wrox Programmer Forums
|
BOOK: Professional Java, JDK 6 Edition ISBN: 978-0-471-77710-6
This is the forum to discuss the Wrox book Professional Java JDK 6 Edition by W. Clay Richardson, Donald Avondolio, Scot Schrager, Mark W. Mitchell, Jeff Scanlon; ISBN: 9780471777106
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Java, JDK 6 Edition ISBN: 978-0-471-77710-6 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 7th, 2010, 02:53 PM
Authorized User
 
Join Date: Jul 2006
Posts: 73
Thanks: 11
Thanked 1 Time in 1 Post
Post error in code!

import java.sql.*;
import java.io.*;
import java.util.*;
publicclass TestDB {
/**
* @param
*/
publicstaticvoid main(String[] args) {
// TODO Auto-generated method stub
{
try
{
runTest();
}
catch (SQLException ex)
{
while (ex !=null)
{
ex.printStackTrace();
ex = ex.getNextException();
}
}
catch (IOException ex)
{
ex.printStackTrace();
}
}
}
/**
*
*/
publicstaticvoid runTest()
throws SQLException, IOException
{
Connection conn = getConnection();
try
{
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE Greetings(Message CHAR(20))");
stat.execute("INSERT INTO Greeting VALUES('Hello World!')");
ResultSet result = stat.executeQuery("SELECT * FROM Greetings");
result.next();
System.out.println(result.getString(1));
stat.execute("DROP TABLE Greetings");
}
finally
{
conn.close();
}
}
/**
*
*/
publicstatic Connection getConnection()
throws SQLException, IOException
{
Properties props = new Properties();
FileInputStream in = new FileInputStream("database.properties");
props.load(in);
in.close();
String drivers = props.getProperty("jdbc.drivers");
if (drivers !=null)
System.setProperty("jdbc", drivers);
String url = props.getProperty("jdbc.url");
String username = props.getProperty("jdbc.username");
String password = props.getProperty("jdbc.password");
return DriverManager.getConnection(url, username, password);
}
}





Similar Threads
Thread Thread Starter Forum Replies Last Post
Error in code nightfox BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 1 January 28th, 2010 04:10 AM
Error in Code NadAf BOOK: Ivor Horton's Beginning Visual C++ 2005 0 February 18th, 2008 11:16 PM
Code error??? emyr BOOK: Beginning Java 2 1 October 31st, 2006 05:47 PM
error with code Mohsin116 Java Basics 1 May 14th, 2006 07:40 AM
Error displayed with error trap code stoneman Access 4 February 28th, 2004 02:53 PM





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