hello i am having a problem when trying to catch tokens from a html form , the form have 3 tokens to fill, password, repeatpassword and email the email token are giving me problems, if i fill an email short like 123#hotmail.com it work fine, but if i fill b0rtzito#hotmail.com it dont work and i dont know the reason, i tried with many combinations unssuccessfull, maybe someone can point me , thanks in advance.
if (command.startsWith("PasswordCreate2"))
{
StringTokenizer create = new StringTokenizer(command, " ");
String pass = null, repeat = null, email = null;
create.nextToken();
if (create.hasMoreTokens())
{
pass = create.nextToken();
}
if (create.hasMoreTokens())
{
repeat = create.nextToken();
}
if (create.hasMoreTokens())
{
email = create.nextToken();
}
if (!((pass == null) || (repeat == null) || (email == null)))
{
if (!pass.equals(repeat))
{
player.sendMessage("The password doesn't match with the repeated one!");
NpcHtmlMessage htm = new NpcHtmlMessage(0);
htm.setHtml(HtmCache.getInstance().getHtm(player.getHtmlPrefix(), htmlPath + "createPassword2.htm"));
player.sendPacket(htm);
return false;
}
if (pass.length() < 3)
{
player.sendMessage("The password is shorter than 3 chars! Please try with a longer one.");
NpcHtmlMessage htm = new NpcHtmlMessage(0);
htm.setHtml(HtmCache.getInstance().getHtm(player.getHtmlPrefix(), htmlPath + "createPassword2.htm"));
player.sendPacket(htm);
return false;
}
if (pass.length() > 30)
{
player.sendMessage("The password is longer than 30 chars! Please try with a shorter one.");
NpcHtmlMessage htm = new NpcHtmlMessage(0);
htm.setHtml(HtmCache.getInstance().getHtm(player.getHtmlPrefix(), htmlPath + "createPassword2.htm"));
player.sendPacket(htm);
return false;
}
if (!(email.contains("#") || email.contains(".")))
{
player.sendMessage("please fill a valid email record you may need it to recover your account.");
NpcHtmlMessage htm = new NpcHtmlMessage(0);
htm.setHtml(HtmCache.getInstance().getHtm(player.getHtmlPrefix(), htmlPath + "createPassword2.htm"));
player.sendPacket(htm);
return false;
}
PlayerSecondPassword.onCreate2(player, pass, email);
}
else
{
NpcHtmlMessage htm = new NpcHtmlMessage(0);
htm.setHtml(HtmCache.getInstance().getHtm(player.getHtmlPrefix(), htmlPath + "createPassword2.htm"));
player.sendPacket(htm);
player.sendMessage("Please fill all of the fields before continuing.");
return false;
}
i always get the return "Please fill all of the fields before continuing"
Related
I got a list(Employees) of employees(object of class Employee) and I try to iterate over that list so I can validate the entered information otherwise rise a message error, It does validate the information and logins in when right information but it raises an error in all others employees checked existent in the list.
String username = FieldUsername.getText();
String password = FieldPassword.getText();
Iterator<Employee> i = Employees.iterator();
while (i.hasNext()) {
Employee o = i.next();
if (o.getName().equals(username) & o.getPassword().equals(password)) {
if (o.getJob().equals("President")) {
JOptionPane.showMessageDialog(null, "Welcome");
UserPresident uno = new UserPresident();
uno.show();
this.dispose();
} else if (o.getJob().equals("Manager")) {
if (o.getArea().equals("Production")) {
JOptionPane.showMessageDialog(null, "Welcome");
UserProductionManager uno = new UserProductionManager();
uno.show();
}else if(o.getArea().equals("Marketing")){
JOptionPane.showMessageDialog(null, "Welcome");
UserMarketingManager uno = new UserMarketingManager();
uno.show();
}else{
JOptionPane.showMessageDialog(null, "Welcome");
UserHRManager uno = new UserHRManager();
uno.show();
}
} else {
JOptionPane.showMessageDialog(null, "Bienvenido");
UserEmployee uno = new UserEmployee();
uno.show();
}
} else {
JOptionPane.showMessageDialog(null, "Username or password is incorrect!");
FieldUsername.setText("");
FieldPassword.setText("");
}
}
Your code will go through each and every employee even if it is correct login it continues to look for another employee to match, you need to make it print Username or password is incorrect! after the loop is done and it hasn't found a match, you could do this by adding a boolean value before the loop and if a correct user was found then change the boolean to not print the Username or password is incorrect!, a simple example:
String username = FieldUsername.getText();
String password = FieldPassword.getText();
Iterator<Employee> i = Employees.iterator();
boolean isCorrectLoginFound = false // Checks for correct login
while (i.hasNext()) {
Employee o = i.next();
if (o.getName().equals(username) && o.getPassword().equals(password)) {
isCorrectLoginFound = true;
if (o.getJob().equals("President")) {
JOptionPane.showMessageDialog(null, "Welcome");
UserPresident uno = new UserPresident();
uno.show();
this.dispose();
break;
} else if (o.getJob().equals("Manager")) {
if (o.getArea().equals("Production")) {
JOptionPane.showMessageDialog(null, "Welcome");
UserProductionManager uno = new UserProductionManager();
uno.show();
break;
}else if(o.getArea().equals("Marketing")){
JOptionPane.showMessageDialog(null, "Welcome");
UserMarketingManager uno = new UserMarketingManager();
uno.show();
break;
}else{
JOptionPane.showMessageDialog(null, "Welcome");
UserHRManager uno = new UserHRManager();
uno.show();
break;
}
} else {
JOptionPane.showMessageDialog(null, "Bienvenido");
UserEmployee uno = new UserEmployee();
uno.show();
break;
}
}
}
if (!isCorrectLoginFound) {
JOptionPane.showMessageDialog(null, "Username or password is incorrect!");
FieldUsername.setText("");
FieldPassword.setText("");
}
I build some software for my mini shop, I really confused with number queue customer who shop in my place. Please someone could help me.
I have a method which content with generate new number of queue from my customer. But when I open my Apps in the next day, I hope the queue is reset into 1 again.
My sytax Java like =
public void acak() {
try {
String generate = "SELECT COALESCE (MAX(no_antrian),0) AS kode from transaksi where tg_transaksi='" + tanggal + "'";
Statement stat = con.createStatement();
ResultSet res = stat.executeQuery(generate);
if (res.next()) {
try {
String kd_barang = res.getString("kode").substring(1);
String AN = "" + (Integer.parseInt(kd_barang) + 1);
String Nol = "";
if (AN.length() == 1) {
Nol = "000";
} else if (AN.length() == 2) {
Nol = "00";
} else if (AN.length() == 3) {
Nol = "0";
} else if (AN.length() == 4) {
Nol = "";
}
lblnoantrian.setText(Nol + AN);
} catch (NumberFormatException ex) {
System.out.println(ex.getMessage());
}
} else {
lblnoantrian.setText("0001");
}
} catch (Exception e) {
e.printStackTrace();
}
}
When I run this program in the next day, I see the eror like :
java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:504)
at java.lang.Integer.parseInt(Integer.java:527)
this eror's refers to:
String AN = "" + (Integer.parseInt(kd_barang) + 1);
maybe anyone can helping me..
this is not the proper use of COALESCE
as its description says
Returns the first non-NULL value in the list, or NULL if there are no non-NULL values.
mysql> SELECT COALESCE(NULL,1);
-> 1
mysql> SELECT COALESCE(NULL,NULL,NULL);
-> NULL
in case there is a empty string so its output would be empty string check
SELECT COALESCE (MAX(NULL),0)
->0
SELECT COALESCE (MAX(''),0)
->
SELECT COALESCE ('',0)
->
as you can see the last two queries returns empty string
replace your query with this query i hope this will work
SELECT
CASE
WHEN COALESCE (MAX(no_antrian), 0) = ''
THEN 0
ELSE COALESCE(MAX(no_antrian), 0)
END AS kodec
FROM
transaksi
WHERE tg_transaksi = '" + tanggal + "' "
This question already has answers here:
How do I compare strings in Java?
(23 answers)
Closed 8 years ago.
Okay, so I even printed out the values of the variables that will be compared to the username and password.
Username luke
Password: password
Username Attempt: luke
Password Attempt: [C#5e15c325
But I'm attempting to input 'password'.... The JPasswordField holds a character array, so I have to use the 'toCharArray' when comparing the char [] 'passwordAttempt' and the String 'pass' that holds the password that is held in a file. Maybe this is why the password attempt is some strange value?
Here's the code of the login() function:
public void login() {
//booleans for error-handling and user authentication
boolean usersInDatabase = true;
boolean userAuthentication = false;
boolean passwordAuthentication = false;
//create the data reader
try {
reader = new Scanner(user1); //user1 is a file
} catch (FileNotFoundException noUsers) {
JOptionPane.showMessageDialog(window, "No users in the database");
usersInDatabase = false;
}
//variables
String user = ""; //variables that will hold the file data which has the
String pass = ""; //username and password
try {
user = reader.nextLine();
pass = reader.nextLine();
}
//you can skip through the error-handling
catch (NoSuchElementException noUsers) {
JOptionPane.showMessageDialog(window, "No users in the database");
usersInDatabase = false;
}
if (usersInDatabase)
{
String userAttempt = usernameField.getText();
String message = ""; //message to display if authentication is unsuccessful
char[] passwordAttempt = passwordField.getPassword();
//okay -- important stuff
//username authentication
if (userAttempt == user) {
userAuthentication = true;
}
else
message += "Incorrect Username -- ";
//password authentication
if (passwordAttempt == pass.toCharArray()) { //check to see if the input matches the string (a character array) that has the value of the file
passwordAuthentication = true;
}
else
message += "Incorrect Password";
if (passwordAuthentication == true && userAuthentication == true)
{
JOptionPane.showMessageDialog(window, "Authorization Successful");
cards.show(cardPanel, "documents");
}
else if(passwordAuthentication == false && userAuthentication == false)
JOptionPane.showMessageDialog(window, message);
//to print out the values for debugging
System.out.println("Username " + user + "\nPassword: " + pass + "\nUsername Attempt: " + userAttempt + "\nPassword Attempt: " + passwordAttempt);
}
}
passwordAttempt == pass.toCharArray()
You cannot compare arrays like this in Java.
Use
Arrays.equals(passwordAttempt, pass.toCharArray());
Or convert them to Strings and compare those (also not by using ==!)
passwordAttemptString.equals(pass);
I am currently having issues in attempting to display data (i.e. itemSummaries with a certain ContainerType) for sites that are ISP, as an example, www.telstra.com.au from Australia
Logging into the site works fine, and the credentials for the site work fine (in other words, it does a refresh which succeeds), however there doesn't appear to be a way to display the itemSummary data
The soap command getItemSummaries, doesn't display data for the item (it displays item data from financial institutions fine). Upon examining the sample code provided by Yodlee for the java soap api, you are meant to use the getItemSummaries1 along with setting ContainerTypes using a SummaryRequest
The problem is that this returns a CoreExceptionFaultMessage. The getItemSummaries1 command is causing the CoreExceptionFaultError. Using different ContainerTypes with different combinations (i.e. ISP, Telephone, Bills) didn't alleviate the issue
The same error message is returned in Yodlees own sample code, i.e. java_soap_example (run the com.yodlee.sampleapps.accountsummary.DisplayBillsData main method and provide the Yodlee login info as command line arguments)
As a reference, the code that is provided by Yodlee sample app is below
Running the getItemSummaries1 command
public void displayBillsData (UserContext userContext)
{
/*SummaryRequest sr = new SummaryRequest(
new String[] {ContainerTypes.BILL, ContainerTypes.TELEPHONE},
new DataExtent[] { DataExtent.getDataExtentForAllLevels(),DataExtent.getDataExtentForAllLevels() }
);*/
SummaryRequest sr = new SummaryRequest();
List list = new List();
list.setElements(new String[] {ContainerTypesHelper.BILL, ContainerTypesHelper.TELEPHONE});
sr.setContainerCriteria(list);
Object[] itemSummaries = null;
List itemSummariesList = null;
try {
itemSummariesList = dataService.getItemSummaries1(userContext, sr);
if (itemSummariesList != null){
itemSummaries = itemSummariesList.getElements();
}
} catch (StaleConversationCredentialsExceptionFault e) {
e.printStackTrace();
} catch (InvalidConversationCredentialsExceptionFault e) {
e.printStackTrace();
} catch (CoreExceptionFault e) {
e.printStackTrace();
} catch (IllegalArgumentTypeExceptionFault e) {
e.printStackTrace();
} catch (IllegalArgumentValueExceptionFault e) {
e.printStackTrace();
} catch (InvalidUserContextExceptionFault e) {
e.printStackTrace();
} catch (IllegalDataExtentExceptionFault e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
}
if (itemSummaries == null || itemSummaries.length == 0) {
System.out.println ("No bills data available");
return;
}
for (int i = 0; i < itemSummaries.length; i++) {
ItemSummary is = (ItemSummary) itemSummaries[i];
displayBillsDataForItem(is);
// Dump the BillsData Object
// dumpBillsDataForItem(is);
}
}
Printing the item data
public void displayBillsDataForItem (ItemSummary is)
{
String containerType = is.getContentServiceInfo ().
getContainerInfo ().getContainerName ();
System.out.println("containerType = " + containerType );
if (!(containerType.equals(ContainerTypesHelper.BILL ) || containerType.equals(ContainerTypesHelper.TELEPHONE)
|| containerType.equals(ContainerTypesHelper.MINUTES))) {
throw new RuntimeException ("displayBillsDataForItem called with " +
"invalid container type: " + containerType);
}
DisplayItemInfo displayItemInfo = new DisplayItemInfo ();
System.out.println("DisplayItemInfo:");
displayItemInfo.displayItemSummaryInfo (is);
System.out.println("");
ItemData id = is.getItemData();
if(id == null){
System.out.println("ItemData == null");
}else{
List accountsList = id.getAccounts();
Object[] accounts = null;
if (accountsList != null){
accounts = accountsList.getElements();
}
if (accounts == null || accounts.length == 0) {
System.out.println ("\tNo accounts");
}else {
for (int accts = 0; accts < accounts.length; accts++) {
BillsData billsData = (BillsData) accounts[accts];
System.out.println("\tAccount Holder: " + billsData.getAccountHolder() );
System.out.println("\tAccount Id: " + billsData.getAccountId());
System.out.println("\tItemAccountId: " + billsData.getItemAccountId() );
System.out.println("\tAccountName: " + billsData.getAccountName() );
System.out.println("\tAccountNumber: " + billsData.getAccountNumber() );
System.out.println("");
// Get List of Bill Objects
List billsList = billsData.getBills();
Object[] bills = null;
if (billsList != null){
bills = billsList.getElements();
}
if (bills == null || bills.length == 0) {
System.out.println ("\t\tNo Bill objects");
}else {
for (int b = 0; b < bills.length; b++) {
Bill bill = (Bill) bills[b];
System.out.println("\t\tBill Account Number: " + bill.getAccountNumber() );
System.out.println("\t\tBill Acct Type: " + bill.getAcctType() );
System.out.println("\t\tBill Due Date: " + Formatter.formatDate(bill.getDueDate().getDate(), Formatter.DATE_SHORT_FORMAT) );
System.out.println("\t\tBill Date: " + Formatter.formatDate(bill.getBillDate().getDate(), Formatter.DATE_SHORT_FORMAT) );
System.out.println("\t\tBill Past Due: "
+ (bill.getPastDue() != null ? bill
.getPastDue().getAmount() : 0.0));
System.out
.println("\t\tBill Last payment: "
+ (bill.getLastPayment() != null ? bill
.getLastPayment()
.getAmount()
: 0.0));
System.out.println("\t\tBill Amount Due: "
+ (bill.getAmountDue() != null ? bill
.getAmountDue().getAmount() : 0.0));
System.out
.println("\t\tBill Min Payment: "
+ (bill.getMinPayment() != null ? bill
.getMinPayment()
.getAmount()
: 0.0));
System.out.println("");
// Get List of AccountUsageData
List acctUsageDataList = bill.getAccountUsages();
Object[] acctUsageData = null;
if (acctUsageDataList != null){
acctUsageData = acctUsageDataList.getElements();
}
if (acctUsageData == null || acctUsageData.length == 0) {
System.out.println ("\t\t\tNo AccountUsageData objects");
}else {
for (int usage = 0; usage < acctUsageData.length; usage++) {
AccountUsageData aud = (AccountUsageData) acctUsageData[usage];
System.out.println("\t\t\tAccount Usage Bill ID: " + aud.getBillId() );
System.out.println("\t\t\tAccount Usage Units Used: " + aud.getUnitsUsed() );
}
}
}
}
System.out.println("");
// Get List of AccountUsageData
List acctUsageDataList = billsData.getAccountUsages();
Object[] acctUsageData = null;
if (acctUsageDataList != null){
acctUsageData = acctUsageDataList.getElements();
}
if (acctUsageData == null || acctUsageData.length == 0) {
System.out.println ("\t\tNo AccountUsageData objects");
}else {
for (int usageData = 0; usageData < acctUsageData.length; usageData++) {
AccountUsageData aud = (AccountUsageData) acctUsageData[usageData];
System.out.println("\t\tAccount Usage Bill ID: " + aud.getBillId() );
System.out.println("\t\tAccount Usage Units Used: " + aud.getUnitsUsed() );
}
}
}
}
}
}
EDIT2:
I have updated the getItemSummaries1 command to look like this
ContainerCriteria bills = new ContainerCriteria();
ContainerCriteria telephone = new ContainerCriteria();
ContainerCriteria isp = new ContainerCriteria();
ContainerCriteria utilities = new ContainerCriteria();
bills.setContainerType(ContainerTypesHelper.BILL);
telephone.setContainerType(ContainerTypesHelper.TELEPHONE);
isp.setContainerType(ContainerTypesHelper.ISP);
utilities.setContainerType(ContainerTypesHelper.UTILITIES);
Object[] containerList = {
bills,telephone,isp,utilities
};
SummaryRequest sr = new SummaryRequest();
List list = new List();
list.setElements(containerList);
sr.setContainerCriteria(list);
The command now executes and works correctly, however its returning a list of 0 elements (using DataExtents with different values didn't change anything). My suspicion is that Telstra.com.au site is broken on Yodlee's end (when a full refresh is done on the Telstra site, Yodlee returns a null for refreshing that specific site).
So far I can see some deviation, so do modify your container criteria as mentioned below
object[] list = {
new ContainerCriteria { containerType = "bills" },
new ContainerCriteria { containerType = "telephone" }
};
sr.containerCriteria = list;
You may additionally provide data extent as follows
DataExtent de = new DataExtent();
dataExtent.startLevel = 0; //as per your needs
dataExtent.endLevel = 0; //as per your needs
object[] list = {
new ContainerCriteria { containerType = "bills", dataExtent = de },
new ContainerCriteria { containerType = "telephone", dataExtent = de }
};
sr.containerCriteria = list;
This should solve your issue. If not then try to get the detail which is is node in the response for the CoreExceptionFaultMessage, this detail may help to diagnose the accurate issue.
To get data for any of the container first you need to add an account for the site belonging to that container. Once you have added the account successfully then only you will be able to pull in the data for such container. Also you can check the tag returned in the getItemSummaries API which has and once this statusCode = 0 then only you have data present for that account.
You can do testing by using the Dummy account which yodlee provides. Please refer to Yodlee Dummy account generator page for more info on Dummy accounts.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
This part is supposed to add a train to the TRAININFO table in my database. I have to use mysql.
So there are some constraints I have to see before adding the train.
jTextField1.getText(); TrainNo. should not have more than 6 characters and it should be an integer.
jTextField2.getText(); TrainName. Should not have more than 30 characters.
jTextField10,jTextField12 have Depttime and araivaltime respectively.
It has 5 characters,"hr:mn" So I have to check if 'hr'<=24 and 'mn'<=59.
If the value of jTextField3.getText()==0 (number of ac1 coaches), then the trainfare for ac1 coaches (tfac1) should also be ==0.
Keeping this in mind I have tried to code it. but it doesn't work.
when ever i run this there is an error message .
Please do tell me where I am wrong.
stacktrace:[Ljava.lang.StackTraceElement;#e596c9
okay heres how it should work:
String m="-",t="-",w="-",th="--",f="-",st="--",s="-",runson;
if(jCheckBox1.isSelected()==true)
{
m="m";
}
if(jCheckBox2.isSelected()==true)
{
t="t";
}
if(jCheckBox3.isSelected()==true)
{
w="w";
}
if(jCheckBox4.isSelected()==true)
{
th="th";
}
if(jCheckBox5.isSelected()==true)
{
f="f";
}
if(jCheckBox6.isSelected()==true)
{
st="st";
}
if(jCheckBox7.isSelected()==true)
{
s="s";
}
runson=m+t+w+th+f+st+s;
int h1=Integer.valueOf(jTextField10.getText().substring(0,2));
int mins1=Integer.valueOf(jTextField10.getText().substring(3,5));
int h2=Integer.valueOf(jTextField12.getText().substring(0,2));
int mins2=Integer.valueOf(jTextField12.getText().substring(2,3));
String time1=jTextField10.getText().substring(0,2)+jTextField10.getText().substring
(2,3)+jTextField10.getText().substring(3,5);
String time2=jTextField12.getText().substring(0,2)+jTextField12.getText().substring
(2,3)+jTextField12.getText().substring(3,5);
String tfac1=jTextField13.getText();
String tfac2=jTextField14.getText();
String tfac3=jTextField15.getText();
String tfsl=jTextField16.getText();
if(Integer.valueOf(jTextField3.getText())==0)
{
tfac1="0";
}
if(Integer.valueOf(jTextField4.getText())==0)
{
tfac2="0";
}
if(Integer.valueOf(jTextField5.getText())==0)
{
tfac3="0";
}
if(Integer.valueOf(jTextField6.getText())==0)
{
tfsl="0";
}
try
{
Class.forName("java.sql.DriverManager");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost/bvdb","root","enter");
Statement stm=con.createStatement();
int n=jTextField1.getText().trim().length();
int m=jTextField2.getText().trim().length();
if( n<=6 && m<=30 && h1<=24 && h2<=24 && mins1<=59 && mins2<=59 )
//This should check the constraints(1,2,3).if the condition is true the following statement will be executed ..else the catch block should be executed. But this doesn't seem to happen when i run the code. There is always an Exception raised.//
{
String q="INSERT INTO TRAININFO VALUE ("+jTextField1.getText()+",'"+jTextField2.getText()+"','"+jTextField9.getText()+"','"+time1+"','"+jTextField11.getText()+"','"+time2+"','"+runson+"',"+tfac1+","+tfac2+ ","+tfac3+","+tfsl+","+jTextField3.getText()+","+jTextField4.getText()+","+jTextField5.getText()+","+jTextField6.getText()+")";
stm.executeUpdate(q);
System.out.print("ADDED");
}
}
catch (Exception e)
{
JOptionPane.showMessageDialog(this,"Enter valid details");
}
s will always be - if !jCheckBox7.isSelected(). Think about it, you have:
if(something) {
...
} else {
s = ...;
}
if(something2) {
...
} else {
s = ...;
}
...
if(somethingN) {
...
} else {
s = "-"; //This will always be executed if !somethingN
}
You might want to have if.. else if instead of if below if.
Also note that it's not a good practice to compare boolean by writing == true. This might lead to problems if you, for example, write = instead of ==. Just write if(isTrue()) instead of if(isTrue() == true).
Basically you need to split your code into many functions. That will make it more readable.
Below is an example of how to structure your code, not a complete working code.
public void InsertTrainInfo() {
String runson = GetRunSon();
Boolean validTime1 = IsTimeValid(jTextField10.getText());
Boolean validTime2 = IsTimeValid(jTextField12.getText());
String time1 = GetTheTime(jTextField10.getText());
String time2 = GetTheTime(jTextField12.getText());
String tfac1 = GetFact(jTextField13.getText());
String tfac2 = GetFact(jTextField14.getText());
String tfac3 = GetFact(jTextField15.getText());
String tfsl = GetFact(jTextField16.getText());
try {
Class.forName("java.sql.DriverManager");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/bvdb", "root", "enter");
Statement stm = con.createStatement();
if (jTextField1.getText().trim().length() <= 6 && jTextField2.getText().trim().length() <= 30 && validTime1 && validTime2) {
String q = "INSERT INTO TRAININFO VALUE (" + jTextField1.getText() + ",'" + jTextField2.getText() + "','" + jTextField9.getText() + "','" + time1 + "','" + jTextField11.getText() + "','" + time2 + "','" + runson + "'," + tfac1 + "," + tfac2 + "," + tfac3 + "," + tfsl + "," + jTextField3.getText() + "," + jTextField4.getText() + "," + jTextField5.getText() + "," + jTextField6.getText() + ")";
stm.executeUpdate(q);
ResetFOrm();
}
} catch (Exception e) {
GetValidDetails();
}
}
Boolean IsTimeValid(String timetext) {
Boolean isOK = false;
try {
int h1 = Integer.valueOf(timetext.substring(0, 2));
int mins1 = Integer.valueOf(timetext.substring(3, 5));
isOK = (h1 <= 24 && mins1 <= 59);
} catch (Exception e) {
isOK = false;
}
return isOK;
}
String GetTheTime(String timetext) {
// do some basic length checks
return timetext.substring(0, 2) + timetext.substring(2, 3) + timetext.substring(3, 5);
}
String GetFact(String facttext) {
String fact = facttext;
if (Integer.valueOf(fact) == 0) {
fact = "0";
}
return fact;
}
void ResetFOrm() {
jTextField1.setEditable(true);
jButton1.setEnabled(true);
jButton2.setEnabled(false);
jButton4.setEnabled(false);
jTextField2.setEditable(false);
jTextField9.setEditable(false);
jTextField10.setEditable(false);
jTextField11.setEditable(false);
jTextField12.setEditable(false);
jTextField13.setEditable(false);
jTextField14.setEditable(false);
jTextField15.setEditable(false);
jTextField16.setEditable(false);
jTextField3.setEditable(false);
jTextField4.setEditable(false);
jTextField5.setEditable(false);
jTextField6.setEditable(false);
jCheckBox1.setEnabled(false);
jCheckBox2.setEnabled(false);
jCheckBox3.setEnabled(false);
jCheckBox4.setEnabled(false);
jCheckBox5.setEnabled(false);
jCheckBox6.setEnabled(false);
jCheckBox7.setEnabled(false);
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
jTextField5.setText("");
jTextField6.setText("");
jTextField7.setText("");
jTextField8.setText("");
jTextField9.setText("");
jTextField10.setText("");
jTextField11.setText("");
jTextField12.setText("");
jTextField13.setText("");
jTextField14.setText("");
jTextField15.setText("");
jTextField16.setText("");
}
void GetValidDetails() {
JOptionPane.showMessageDialog(this, "Enter valid details");
jTextField9.setEditable(true);
jTextField10.setEditable(true);
jTextField11.setEditable(true);
jTextField12.setEditable(true);
jTextField13.setEditable(true);
jTextField14.setEditable(true);
jTextField15.setEditable(true);
jTextField16.setEditable(true);
jTextField2.setEditable(true);
jTextField3.setEditable(true);
jTextField4.setEditable(true);
jTextField5.setEditable(true);
jTextField6.setEditable(true);
jCheckBox1.setEnabled(true);
jCheckBox2.setEnabled(true);
jCheckBox3.setEnabled(true);
jCheckBox4.setEnabled(true);
jCheckBox5.setEnabled(true);
jCheckBox6.setEnabled(true);
jCheckBox7.setEnabled(true);
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
jTextField5.setText("");
jTextField6.setText("");
jTextField7.setText("");
jTextField8.setText("");
jTextField9.setText("");
jTextField10.setText("");
jTextField11.setText("");
jTextField12.setText("");
jTextField13.setText("");
jTextField14.setText("");
jTextField15.setText("");
jTextField16.setText("");
jCheckBox1.setSelected(false);
jCheckBox2.setSelected(false);
jCheckBox3.setSelected(false);
jCheckBox4.setSelected(false);
jCheckBox5.setSelected(false);
jCheckBox6.setSelected(false);
jCheckBox7.setSelected(false);
}
String GetRunSon() {
String m = "-", t = "-", w = "-", th = "--", f = "-", st = "--", s = "-", runson;
if (jCheckBox1.isSelected()) {
m = "m";
}
if (jCheckBox2.isSelected()) {
t = "t";
}
if (jCheckBox3.isSelected()) {
w = "w";
}
if (jCheckBox4.isSelected()) {
th = "th";
}
if (jCheckBox5.isSelected()) {
f = "f";
}
if (jCheckBox6.isSelected()) {
st = "st";
}
if (jCheckBox7.isSelected()) {
s = "s";
}
runson = m + t + w + th + f + st + s;
return runson;
}