Siemka chciałbym pokombinawac z bazami danych + java I już na wstępie mam problem :) Korzystam z ksiązki Java 2 Techniki zaawansowane kod przepisuje słowo w słowo
package projekt;
import java.sql.*;
import java.io.*;
import java.util.*;
public class Main
{
public static void main(String args[])
{
try
{
runTest();
}
catch (SQLException ex)
{
while(ex != null)
{
ex.printStackTrace();
ex = ex.getNextException();
}
}
catch(IOException ex)
{
ex.printStackTrace();
}
}
public static void runTest() throws SQLException, IOException
{
Connection conn = getConnection();
try
{
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE Greetings (Message CHAR(20))");
stat.execute("INSERT INTO Greetings VALUES ('HEllo, word!')");
ResultSet result = stat.executeQuery("SELECT * FROM Greetings");
result.next();
System.out.println(result.getString(1));
stat.execute("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 drives = props.getProperty("jdbc.driver");
if ( drives != null)
System.setProperty("jdbc.drivers",drives);
String url = props.getProperty("jdbc.url");
String username = props.getProperty("jdbc.username");
String password = props.getProperty("jdbc.password");
return DriverManager.getConnection(url,username,password);
}
}
a błędy jakie mi sypie to java.io.FileNotFoundException: database.properties (Nie można odnaleźć określonego pliku)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at projekt.Main.getConnection(Main.java:55)
at projekt.Main.runTest(Main.java:33)
at projekt.Main.main(Main.java:15)
nie wiem czy to ważne ale używam NetBeans'a proszę o pomoc pozdrawiam