Witam
Chciałbym nauczyć się pracy z relacyjnymi bazami danych.
W Eclipse mam program testujący poprawne połączenie z baza :
Test.java
package Oppp;
import java.sql.*;
import java.io.*;
import java.util.*;
public class Test
{
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 VALUE ('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);
}
}
database.properties
jdbc.drivers=org.postgresql.JDBCDriver
jdbc.url=jdbc:postgresql:COREJAVA
jdbc.username=postgres
jdbc.password=sql8
Bazę mam w PostgreSQL 8.3
A w czasie kompilacji rgramu wyskakuje
org.postgresql.util.PSQLException: ERROR: syntax error at or near "VALUE"
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1592)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1327)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:192)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:451)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:336)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:328)
at Oppp.Test.runTest(Test.java:37)
at Oppp.Test.main(Test.java:13)
już nie mam siły co z tym zrobić ??? proszę o pomoc