我与JDBC初学者...我有这段代码运行的一个问题:
此代码使用appache德比,为了使工作我第一次开始的德比服务器..
java -jar "C:\Program Files\Sun\JavaDB\lib\derbyrun.jar" server start
然后启动程序
java -classpath derbyclient.jar -jar TestDB.jar
我设置类路径C:\ Program Files文件\太阳\ JavaDB之外\ LIB \的derby.jar
而且我一直都想与该异常
值java.sql.SQLException:德比://本地主机:找到JDBC没有合适的驱动器1527 / BOOKDB;创建=真在java.sql.DriverManager.getConnection(DriverManager.java:602)在java.sql.DriverManager.getConnection( DriverManager.java:185)在TestDB.getConnection(TestDB.java:63)在TestDB.runTest(TestDB.java:20)在TestDB.main(TestDB.java:11)
import java.sql.*;
import java.io.*;
import java.util.*;
class TestDB
{
public static void main(String args[])
{
try
{
runTest();
}
catch (SQLException ex)
{
for (Throwable t : ex)
t.printStackTrace();
}
catch (IOException ex)
{
ex.printStackTrace();
}
}
public static void runTest() throws SQLException, IOException
{
Connection conn = getConnection();
try
{
Statement stat = conn.createStatement();
stat.executeUpdate("CREATE TABLE Greetings (Message CHAR(20))");
stat.executeUpdate("INSERT INTO Greetings VALUES ('Hello, World!')");
ResultSet result = stat.executeQuery("SELECT * FROM Greetings");
if (result.next())
System.out.println(result.getString(1));
result.close();
stat.executeUpdate("DROP TABLE Greetings");
}
finally
{
conn.close();
}
}
public static 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", 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);
}
}