javadb

How can I identify columns when SELECTing from multiple tables with JDBC?

冷暖自知 提交于 2021-02-18 22:13:05
问题 I have two tables that I join on the id-column, they look like: +-------+ | users | +----+--+---+ | id | name | +----+------+ +-------+ | posts | +-------+------+---------+ | id | user_id | message | +----+---------+---------+ And now I want to select all posts and include the username, with: SELECT * FROM posts, users WHERE user_id = users.id And then I try to get the values with: ResultSet rs = // SQL if(rs.next()) { rs.getInt("posts.id"); ... } But I get SQLException when executing rs

How can I identify columns when SELECTing from multiple tables with JDBC?

醉酒当歌 提交于 2021-02-18 22:09:52
问题 I have two tables that I join on the id-column, they look like: +-------+ | users | +----+--+---+ | id | name | +----+------+ +-------+ | posts | +-------+------+---------+ | id | user_id | message | +----+---------+---------+ And now I want to select all posts and include the username, with: SELECT * FROM posts, users WHERE user_id = users.id And then I try to get the values with: ResultSet rs = // SQL if(rs.next()) { rs.getInt("posts.id"); ... } But I get SQLException when executing rs

INSERT, and get the auto-incremented value

倾然丶 夕夏残阳落幕 提交于 2020-01-11 09:48:27
问题 Consider the following table: create table language ( id integer generated always as identity (START WITH 1, INCREMENT BY 1), name long varchar, constraint language_pk primary key (id) ); To which I'd insert an entry this way. insert into language(name) values ('value'); How does one know what value for id was created? Just doing a SELECT using the name field is not valid, because there can be duplicate entries. 回答1: Through plain SQL: insert into language(name) values ('value'); SELECT

Truncate a VARCHAR to specific length in Derby AUTOMATICALLY

半世苍凉 提交于 2020-01-04 07:35:31
问题 How can I truncate a VARCHAR to the table field length AUTOMATICALLY in Derby using SQL? To be specific: CREATE TABLE A ( B VARCHAR(2) ); INSERT INTO A B VALUES ('1234'); would throw a SQLException: A truncation error was encountered trying to shrink VARCHAR '123' to length 2. Is there a easy way to suppress this exception? 回答1: No. You should chop it off after checking the meta-data. Or if you don't wanna check the meta-data everytime, then you must keep both your code and database in sync.

Truncate a VARCHAR to specific length in Derby AUTOMATICALLY

眉间皱痕 提交于 2020-01-04 07:35:27
问题 How can I truncate a VARCHAR to the table field length AUTOMATICALLY in Derby using SQL? To be specific: CREATE TABLE A ( B VARCHAR(2) ); INSERT INTO A B VALUES ('1234'); would throw a SQLException: A truncation error was encountered trying to shrink VARCHAR '123' to length 2. Is there a easy way to suppress this exception? 回答1: No. You should chop it off after checking the meta-data. Or if you don't wanna check the meta-data everytime, then you must keep both your code and database in sync.

JavaDB having port connection error.

↘锁芯ラ 提交于 2019-12-31 03:56:06
问题 I am using JavaDB for the first time and I am having trouble getting my program to run. Whenever I run it I get this error: "Error connecting to server localhost on port 1527 with message Connection refused: connect" My database and code are all setup okay as when I ran it on someone elses computer it worked fine, but on mine it doesn't. I'm using Netbeans 7.3.1 as that is the version I have to use for school. I am not sure what is causing this and I could really use some help. If you have

Database not found error in Apache Derby

穿精又带淫゛_ 提交于 2019-12-29 09:08:22
问题 First, this is my first time with Apache Derby. I am using netbeans, willing to use embedded apache derby, and I followed the following tutorial for configuring and installing the database http://netbeans.org/kb/docs/ide/java-db.html#starting The attached image will show my database status in netbeans My database name is "contact". Table name is "FRIENDS". Following is my test code DatabaseConnector.java import java.sql.*; public class DataBaseConnector { private Connection con; public

Database not found error in Apache Derby

落爺英雄遲暮 提交于 2019-12-29 09:07:15
问题 First, this is my first time with Apache Derby. I am using netbeans, willing to use embedded apache derby, and I followed the following tutorial for configuring and installing the database http://netbeans.org/kb/docs/ide/java-db.html#starting The attached image will show my database status in netbeans My database name is "contact". Table name is "FRIENDS". Following is my test code DatabaseConnector.java import java.sql.*; public class DataBaseConnector { private Connection con; public

attach derby database into jar file

巧了我就是萌 提交于 2019-12-24 07:10:03
问题 I am midway through a database application(SWING). I am using Java DB and NetBeans 7.1.2. Within the IDE, the app runs good, provided I initially connect the database manually in the 'services' window. Also, I have added the derby.jar and derbyclient.jar files to the libraries. But when running the app from the "dist" folder, it fails to connect to the database. I want to know whether i can attach the db within the jar file so that i can run the app from outside the IDE. Thank you. 回答1: You

How to create table in lower case name - JavaDB/Derby?

那年仲夏 提交于 2019-12-22 18:06:10
问题 Is it possible to create table and it's name in lower case using JavaDB/Derby? To check if table exists I'm using: ResultSet rs = dbmd.getTables(null, "APP", "user_properties", null); if (!rs.next()) {/*do something*/}; But table name 'user_properties' must mach the case in catalog. 回答1: Derby follows the ANSI standard which requires unquoted identifiers to be folded to uppercase. So, the following statement: create table user_properties ( id integer not null ); will create a table with then