db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Satheesh Bandaram <sathe...@Sourcery.Org>
Subject Re: SQL Exception: Connection refused : Invalid authentication.
Date Fri, 21 Oct 2005 23:29:55 GMT
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-15"
 http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
I think I know why your program is not working... You are not passing
username/password as the URL attributes... If you change:<br>
<br>
            Connection conn  = 
DriverManager.getConnection("jdbc:derby:/tmp/TestDB", prop);
<br>
<b>To </b><br>
            Connection conn  = 
DriverManager.getConnection("jdbc:derby:/tmp/TestDB;user=username;password=password");<br>
<br>
It should work. Or you can create the Properties object and set
username/password using <b>correct property names, user/password</b>,
it should also work. Currently, you are setting username/password using:<br>
<br>
    prop.setProperty("derby.user.username", "password");
<br>
<br>
Once you do manage to connect to your database, you may notice other
issues... When you connect to Derby using a valid username, your schema
is the 'username', not the default APP.<br>
<br>
Satheesh<br>
<br>
Arne Anka wrote:
<blockquote cite="midop.syz354vcp1z4zz@komhem" type="cite">hi,
  <br>
i'm fairly new to derby and experience a problem absolutely not clear
to  me.
  <br>
programming an java-application (rcp-based, if it matters) i create a 
database programmatically with two tables, reading and writing works
well.
  <br>
i restart my application, try to access the db with 
_exactly_the_same_code_ ... and get the error mentioned in the subject!
  <br>
-------- Derby Information --------
  <br>
JRE - JDBC: J2SE 5.0 - JDBC 3.0
  <br>
[/home/arne/Eclipse/.plugins/eclipse/plugins/org.apache.derby.core_10.1.1/derby.jar] 
10.1.1.0 - (208786)
  <br>
[/home/arne/Eclipse/.plugins/eclipse/plugins/org.apache.derby.core_10.1.1/derbyclient.jar] 
10.1.1.0 - (208786)
  <br>
[/home/arne/Eclipse/.plugins/eclipse/plugins/org.apache.derby.core_10.1.1/derbytools.jar] 
10.1.1.0 - (208786)
  <br>
[/home/arne/Eclipse/.plugins/eclipse/plugins/org.apache.derby.core_10.1.1/derbynet.jar] 
10.1.1.0 - (208786)
  <br>
------------------------------------------------------
  <br>
  <br>
it works well, if i create and access the db in a single session. if
try  to access the db in another session later on,
  <br>
Connection conn  =
DriverManager.getConnection("jdbc:derby:/tmp/TestDB",  prop); yields
  <br>
  <br>
SQL Exception: Connection refused : Invalid authentication.
  <br>
        at
org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown  Source)
  <br>
        at
org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown  Source)
  <br>
        at
org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown  Source)
  <br>
        at 
org.apache.derby.impl.jdbc.EmbedConnection.newSQLException(Unknown
Source)
  <br>
        at 
org.apache.derby.impl.jdbc.EmbedConnection.checkUserCredentials(Unknown 
Source)
  <br>
        at
org.apache.derby.impl.jdbc.EmbedConnection.&lt;init&gt;(Unknown 
Source)
  <br>
        at
org.apache.derby.impl.jdbc.EmbedConnection30.&lt;init&gt;(Unknown 
Source)
  <br>
        at
org.apache.derby.jdbc.Driver30.getNewEmbedConnection(Unknown  Source)
  <br>
        at org.apache.derby.jdbc.InternalDriver.connect(Unknown Source)
  <br>
        at java.sql.DriverManager.getConnection(DriverManager.java:525)
  <br>
        at java.sql.DriverManager.getConnection(DriverManager.java:140)
  <br>
        at 
de.itcputbus.marinasw.main.dblocal.LocalDBStuff.readEmbedded(LocalDBStuff.java:181)
  <br>
        ...
  <br>
  <br>
code to create and access (if you find a typo -- the code i use is 
syntactically correct, i probabyl introduced it here)
  <br>
  <br>
  <br>
 public static void initEmbedded() {
  <br>
                try{
  <br>
                   //prop is a java.utils.Properties instance
  <br>
                   prop.setProperty("derby.user.username", "password");
  <br>
                   prop.setProperty("derby.system.home", 
dbpath.removeLastSegments(1).toOSString());
  <br>
                  
prop.setProperty("derby.connection.requireAuthentication",  "true");
  <br>
                   prop.setProperty("derby.database.fullAccessUsers", 
"dba,username");
  <br>
                   prop.setProperty("derby.authentication.provider", 
"BUILTIN");
  <br>
                    System.setProperty("derby.system.home", 
dbpath.removeLastSegments(1).toOSString());
  <br>
  <br>
                   
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
  <br>
  <br>
                }catch(Exception e){
  <br>
                    e.printStackTrace();
  <br>
                }
  <br>
        }
  <br>
    }
  <br>
  <br>
    public static void createEmbedded(){
  <br>
        try{
  <br>
            Connection conn  = 
DriverManager.getConnection("jdbc:derby:/tmp/TestDB;create=true",
prop);
  <br>
            Statement s = conn.createStatement();
  <br>
  <br>
            s.addBatch("CALL 
SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY('derby.connection.requireAuthentication','true')");
  <br>
            s.addBatch("CALL 
SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY('derby.user.username','password')");
  <br>
            s.addBatch("CALL 
SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY('derby.database.fullAccessUsers', 
'dba,username')");
  <br>
            s.addBatch("CALL 
SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY('derby.authentication.provider', 
'BUILTIN')");
  <br>
  <br>
            s.executeBatch();
  <br>
  <br>
            try{//derby does not know "drop table if exists" but yields
an  error if the table to drop not exists -- so we need a workaround
...
  <br>
                s.execute("drop table custs");
  <br>
                s.execute("drop table orders");
  <br>
            }catch(SQLException e) {}
  <br>
  <br>
            s.addBatch("create table custs (id char(5) not null, name 
char(40) not null, primary key(id))");
  <br>
            s.addBatch("create table orders (id char(8) not null,
custid  char(5) not null, total integer, primary key(id, custid))");
  <br>
  <br>
            s.executeBatch();
  <br>
  <br>
            s.addBatch("insert into custs values('1', 'John Milton')");
  <br>
            s.addBatch("insert into custs values('2', 'Duns Scotus')");
  <br>
  <br>
            s.executeBatch();
  <br>
  <br>
            s.addBatch("insert into orders values('0001', '1',
12345)");
  <br>
            s.addBatch("insert into orders values('0002', '2', 145)");
  <br>
  <br>
            s.executeBatch();
  <br>
  <br>
            conn.close();
  <br>
        }catch(Exception e){
  <br>
            e.printStackTrace();
  <br>
        }
  <br>
    }
  <br>
  <br>
    public static void readEmbedded(){
  <br>
        try{
  <br>
            Connection conn  = 
DriverManager.getConnection("jdbc:derby:/tmp/TestDB", prop);
  <br>
            ResultSet rs=conn.createStatement().executeQuery("select * 
from custs, orders");
  <br>
            while(rs.next()) {
  <br>
                System.out.println("-: "+rs.getString(1)+" | 
"+rs.getString(2)+" | "+rs.getString(3)+" | "+rs.getString(4)+" | 
"+rs.getString(5));
  <br>
            }
  <br>
            conn.close();
  <br>
        }catch(Exception e){
  <br>
            e.printStackTrace();
  <br>
        }
  <br>
    }
  <br>
  <br>
  <br>
  <br>
  <br>
</blockquote>
</body>
</html>

Mime
View raw message