db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jim Crowell <JimCrow...@EMail.com>
Subject Java stand alone application question?
Date Mon, 01 Jun 2009 20:50:15 GMT

I am writing a Java Stand-Alone Application which is trying to use the Derby
Data Base.

It looks like my Java code is setting up the DB Table OK but when I do the
table insert
I have problems. No errors occur but a Java method I wrote to display the
table yields no inserts.

Therefore, I tried to use the 'ij' tool to see if the inserts are there or

The following Java method was used to create the table in my Java App.

public static void createTable(
	Connection conn,
	String tableName) {
	//	If the given Table does not exist in the Data Base...
	if (!tableExist(conn, tableName)) {
		try {
			statement = conn.createStatement();
				"create table "+tableName+"(" +
    	        		"nameKey varchar(30) NOT NULL PRIMARY KEY, "+
    	        		"value varchar(300))");
			} catch (SQLException sqle) {
			}	//	End 'catch'...
		}	//	End 'tableExist : false IF...
	else {
		"Given table ["+tableName+"] already exist in the "+
		QUOTE+dbName+QUOTE+" Derby Data Base.."+EOP+
	}	//	End 'tableExist : false ELSE...
}	//	End 'createTable' Method...

Being new to ‘ij’ I have struggled trying to learn how to display the table
generated above.

The following 'ij' presentation is derived from a sql script file.

The connection is successful and the table generated by the above code [ab]
is seen with the
"SHOW TABLES" 'ij' command but is not seen by the subsequent 'ij' / 'sql'

ij version 10.5
ij> -- ENTERED 'connect.ij' SCRIPT FILE...
PROTOCOL 'jdbc:derby:';
ij> -- connect 'C:\SLPlus\db\BJCROW4936SYNYaBcDeF';
connect 'C:\SLPlus\db\BJCROW4936SYNYaBcDeF';
ij> -- show tables...
TABLE_SCHEM         |TABLE_NAME                    |REMARKS             
SYS                 |SYSALIASES                    |                    
SYS                 |SYSCHECKS                     |                    
SYS                 |SYSCOLPERMS                   |                    
SYS                 |SYSCOLUMNS                    |                    
SYS                 |SYSCONGLOMERATES              |                    
SYS                 |SYSCONSTRAINTS                |                    
SYS                 |SYSDEPENDS                    |                    
SYS                 |SYSFILES                      |                    
SYS                 |SYSFOREIGNKEYS                |                    
SYS                 |SYSKEYS                       |                    
SYS                 |SYSROLES                      |                    
SYS                 |SYSROUTINEPERMS               |                    
SYS                 |SYSSCHEMAS                    |                    
SYS                 |SYSSTATEMENTS                 |                    
SYS                 |SYSSTATISTICS                 |                    
SYS                 |SYSTABLEPERMS                 |                    
SYS                 |SYSTABLES                     |                    
SYS                 |SYSTRIGGERS                   |                    
SYS                 |SYSVIEWS                      |                    
SYSIBM            |SYSDUMMY1                     |                    
ME                  |AB                            |                    

21 rows selected
ij> autocommit off;
ij> prepare abInsert as 'INSERT INTO ab VALUES(?, ?, ?)';
ERROR 42X05: Table/View 'AB' does not exist.
ij> execute abInsert using 'VALUES
   (''abc'', ''def'')';
IJ ERROR: Unable to establish prepared statement ABINSERT
ij> commit;
ij> select * from ab;
ERROR 42X05: Table/View 'AB' does not exist.

The above script was designed to show some attempts I have made to insert
some dummy items into the table.

The following Java method shows the code I am using to insert 6 rows
into the 'Address Book' table with each 'keyName' being a unique primary

public static void insertAddressBookName(
		Connection conn,
		String nameKey,
		String [] segments) {
		ArrayList<String> list = new ArrayList<String>(maxSegments);
		int nSegments = segments.length;
		try {
			Statement sta = conn.createStatement();
			int count = 0;
    		for (int i=0; i<maxSegments; i++) {
    			String keyName = nameKey+abKeyCodes[i];
			//	String v = " VALUES ("+keyName+COMMA+segments[i]+")";
    			int c =
    				sta.executeUpdate("INSERT INTO AB"+
				" VALUES ('"+keyName+"','"+segments[i]+"')");
    			count += c;
    			System.out.println("c|count|keyName|value = "+
    		}	//	End 'segments' LOOP...
}	//	End ‘insertAddressBookName’ Method...

My initial code used the 'Prepared Statement' approach but I changed to the
more direct but less effective method during my debug process.

 Any suggestions on what I am missing?

View this message in context: http://www.nabble.com/Java-stand-alone-application-question--tp23822083p23822083.html
Sent from the Apache Derby Developers mailing list archive at Nabble.com.

View raw message