Java With mysql
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I have a mysql table and records as follows.
create table if not exists price (
price_id varchar(30) not null,
econ_price float(10,3),
business_price float(10,3),
platinum_price float(10,3),
primary key(price_id)
);
insert into price values('1',334,556,788);
insert into price values('2',3500,5500,7000);
insert into price values('3',1000,5500,7400);
insert into price values('4',1000,5500,7400);
If I know the price type (econ or business or platinum) and price_id, how can I want to get the price? These are my java codes.
public int setPrice(String price_id, String type){
.........................
return price;
}
int price1 = setPrice(3,'econ');
int price2 = setPrice(4,'platinum');
Can anyone help me?
java mysql jdbc
add a comment |
I have a mysql table and records as follows.
create table if not exists price (
price_id varchar(30) not null,
econ_price float(10,3),
business_price float(10,3),
platinum_price float(10,3),
primary key(price_id)
);
insert into price values('1',334,556,788);
insert into price values('2',3500,5500,7000);
insert into price values('3',1000,5500,7400);
insert into price values('4',1000,5500,7400);
If I know the price type (econ or business or platinum) and price_id, how can I want to get the price? These are my java codes.
public int setPrice(String price_id, String type){
.........................
return price;
}
int price1 = setPrice(3,'econ');
int price2 = setPrice(4,'platinum');
Can anyone help me?
java mysql jdbc
Are you asking how to code a dao method to retrieve the price from the database?
– John Camerin
Nov 25 '18 at 5:07
It's make me confuse , what actually you want to say? .
– Md. Mokammal Hossen Farnan
Nov 25 '18 at 5:08
I cannot understand how to write that mysql query. But I can find the price if my table is like follows............................... create table if not exists price ( price_id varchar(30) not null, type varchar(30),price float(10,3) , primary key(price_id,type) );
– user8878908
Nov 25 '18 at 5:12
Then I can use ,,,,,,,, SELECT price FROM price WHERE price_id=? AND type =?;
– user8878908
Nov 25 '18 at 5:14
But in this type of table, it is difficult to write the query.
– user8878908
Nov 25 '18 at 5:14
add a comment |
I have a mysql table and records as follows.
create table if not exists price (
price_id varchar(30) not null,
econ_price float(10,3),
business_price float(10,3),
platinum_price float(10,3),
primary key(price_id)
);
insert into price values('1',334,556,788);
insert into price values('2',3500,5500,7000);
insert into price values('3',1000,5500,7400);
insert into price values('4',1000,5500,7400);
If I know the price type (econ or business or platinum) and price_id, how can I want to get the price? These are my java codes.
public int setPrice(String price_id, String type){
.........................
return price;
}
int price1 = setPrice(3,'econ');
int price2 = setPrice(4,'platinum');
Can anyone help me?
java mysql jdbc
I have a mysql table and records as follows.
create table if not exists price (
price_id varchar(30) not null,
econ_price float(10,3),
business_price float(10,3),
platinum_price float(10,3),
primary key(price_id)
);
insert into price values('1',334,556,788);
insert into price values('2',3500,5500,7000);
insert into price values('3',1000,5500,7400);
insert into price values('4',1000,5500,7400);
If I know the price type (econ or business or platinum) and price_id, how can I want to get the price? These are my java codes.
public int setPrice(String price_id, String type){
.........................
return price;
}
int price1 = setPrice(3,'econ');
int price2 = setPrice(4,'platinum');
Can anyone help me?
java mysql jdbc
java mysql jdbc
edited Apr 14 at 6:27
Mark Rotteveel
62.4k1479123
62.4k1479123
asked Nov 25 '18 at 4:59
user8878908
Are you asking how to code a dao method to retrieve the price from the database?
– John Camerin
Nov 25 '18 at 5:07
It's make me confuse , what actually you want to say? .
– Md. Mokammal Hossen Farnan
Nov 25 '18 at 5:08
I cannot understand how to write that mysql query. But I can find the price if my table is like follows............................... create table if not exists price ( price_id varchar(30) not null, type varchar(30),price float(10,3) , primary key(price_id,type) );
– user8878908
Nov 25 '18 at 5:12
Then I can use ,,,,,,,, SELECT price FROM price WHERE price_id=? AND type =?;
– user8878908
Nov 25 '18 at 5:14
But in this type of table, it is difficult to write the query.
– user8878908
Nov 25 '18 at 5:14
add a comment |
Are you asking how to code a dao method to retrieve the price from the database?
– John Camerin
Nov 25 '18 at 5:07
It's make me confuse , what actually you want to say? .
– Md. Mokammal Hossen Farnan
Nov 25 '18 at 5:08
I cannot understand how to write that mysql query. But I can find the price if my table is like follows............................... create table if not exists price ( price_id varchar(30) not null, type varchar(30),price float(10,3) , primary key(price_id,type) );
– user8878908
Nov 25 '18 at 5:12
Then I can use ,,,,,,,, SELECT price FROM price WHERE price_id=? AND type =?;
– user8878908
Nov 25 '18 at 5:14
But in this type of table, it is difficult to write the query.
– user8878908
Nov 25 '18 at 5:14
Are you asking how to code a dao method to retrieve the price from the database?
– John Camerin
Nov 25 '18 at 5:07
Are you asking how to code a dao method to retrieve the price from the database?
– John Camerin
Nov 25 '18 at 5:07
It's make me confuse , what actually you want to say? .
– Md. Mokammal Hossen Farnan
Nov 25 '18 at 5:08
It's make me confuse , what actually you want to say? .
– Md. Mokammal Hossen Farnan
Nov 25 '18 at 5:08
I cannot understand how to write that mysql query. But I can find the price if my table is like follows............................... create table if not exists price ( price_id varchar(30) not null, type varchar(30),price float(10,3) , primary key(price_id,type) );
– user8878908
Nov 25 '18 at 5:12
I cannot understand how to write that mysql query. But I can find the price if my table is like follows............................... create table if not exists price ( price_id varchar(30) not null, type varchar(30),price float(10,3) , primary key(price_id,type) );
– user8878908
Nov 25 '18 at 5:12
Then I can use ,,,,,,,, SELECT price FROM price WHERE price_id=? AND type =?;
– user8878908
Nov 25 '18 at 5:14
Then I can use ,,,,,,,, SELECT price FROM price WHERE price_id=? AND type =?;
– user8878908
Nov 25 '18 at 5:14
But in this type of table, it is difficult to write the query.
– user8878908
Nov 25 '18 at 5:14
But in this type of table, it is difficult to write the query.
– user8878908
Nov 25 '18 at 5:14
add a comment |
1 Answer
1
active
oldest
votes
Per the post, you already know the type. So, a very blunt approach would be to have a switch/conditional select statements based on the known types.
...
if ("econ".equals(type)) {
sql = "select econ_price from price where price_id = ?";
} else if ("platinum".equals(type) {
sql = "select platinum_price from price where price_id = ?";
} else {
...
}
Note, this is a very blunt approach and there may be other ways to solve the problem. However, this does answer the question asked.
1
Code only answers are discouraged. Please add some explanation as to how this solves the problem. From Review
– Nick
Apr 14 at 4:01
It would be great if you can add more details
– vimuth
Apr 14 at 4:29
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53464784%2fjava-with-mysql%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Per the post, you already know the type. So, a very blunt approach would be to have a switch/conditional select statements based on the known types.
...
if ("econ".equals(type)) {
sql = "select econ_price from price where price_id = ?";
} else if ("platinum".equals(type) {
sql = "select platinum_price from price where price_id = ?";
} else {
...
}
Note, this is a very blunt approach and there may be other ways to solve the problem. However, this does answer the question asked.
1
Code only answers are discouraged. Please add some explanation as to how this solves the problem. From Review
– Nick
Apr 14 at 4:01
It would be great if you can add more details
– vimuth
Apr 14 at 4:29
add a comment |
Per the post, you already know the type. So, a very blunt approach would be to have a switch/conditional select statements based on the known types.
...
if ("econ".equals(type)) {
sql = "select econ_price from price where price_id = ?";
} else if ("platinum".equals(type) {
sql = "select platinum_price from price where price_id = ?";
} else {
...
}
Note, this is a very blunt approach and there may be other ways to solve the problem. However, this does answer the question asked.
1
Code only answers are discouraged. Please add some explanation as to how this solves the problem. From Review
– Nick
Apr 14 at 4:01
It would be great if you can add more details
– vimuth
Apr 14 at 4:29
add a comment |
Per the post, you already know the type. So, a very blunt approach would be to have a switch/conditional select statements based on the known types.
...
if ("econ".equals(type)) {
sql = "select econ_price from price where price_id = ?";
} else if ("platinum".equals(type) {
sql = "select platinum_price from price where price_id = ?";
} else {
...
}
Note, this is a very blunt approach and there may be other ways to solve the problem. However, this does answer the question asked.
Per the post, you already know the type. So, a very blunt approach would be to have a switch/conditional select statements based on the known types.
...
if ("econ".equals(type)) {
sql = "select econ_price from price where price_id = ?";
} else if ("platinum".equals(type) {
sql = "select platinum_price from price where price_id = ?";
} else {
...
}
Note, this is a very blunt approach and there may be other ways to solve the problem. However, this does answer the question asked.
edited Apr 15 at 14:55
answered Nov 25 '18 at 5:06
John CamerinJohn Camerin
436212
436212
1
Code only answers are discouraged. Please add some explanation as to how this solves the problem. From Review
– Nick
Apr 14 at 4:01
It would be great if you can add more details
– vimuth
Apr 14 at 4:29
add a comment |
1
Code only answers are discouraged. Please add some explanation as to how this solves the problem. From Review
– Nick
Apr 14 at 4:01
It would be great if you can add more details
– vimuth
Apr 14 at 4:29
1
1
Code only answers are discouraged. Please add some explanation as to how this solves the problem. From Review
– Nick
Apr 14 at 4:01
Code only answers are discouraged. Please add some explanation as to how this solves the problem. From Review
– Nick
Apr 14 at 4:01
It would be great if you can add more details
– vimuth
Apr 14 at 4:29
It would be great if you can add more details
– vimuth
Apr 14 at 4:29
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53464784%2fjava-with-mysql%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Are you asking how to code a dao method to retrieve the price from the database?
– John Camerin
Nov 25 '18 at 5:07
It's make me confuse , what actually you want to say? .
– Md. Mokammal Hossen Farnan
Nov 25 '18 at 5:08
I cannot understand how to write that mysql query. But I can find the price if my table is like follows............................... create table if not exists price ( price_id varchar(30) not null, type varchar(30),price float(10,3) , primary key(price_id,type) );
– user8878908
Nov 25 '18 at 5:12
Then I can use ,,,,,,,, SELECT price FROM price WHERE price_id=? AND type =?;
– user8878908
Nov 25 '18 at 5:14
But in this type of table, it is difficult to write the query.
– user8878908
Nov 25 '18 at 5:14