logo
Tags down

shadow

I am doing an attendence program with java and mySQL, and its not working well with me. Here's the code:


By : Johnyburd
Date : September 16 2020, 12:00 PM
With these it helps You have a few problem in your code.
Fist of all ResultSet.next() is not reasuble. If you write :
code :
System.out.println(rs.next());
boolean next = rs.next();
System.out.println( next );
if ( next ) {  
    /*
 */

/*
 * Use an external method to access the connection, better in an external data source or factory.
 */
public Connection getConnection() throws Exception {
    Class.forName("com.mysql.jdbc.Driver");
    return DriverManager.getConnection("jdbc:mysql://localhost:3306/Attend", "rt", "Tester_2020");
}

/*
 * Usually is better to use a logging facility (slf4j, log4j, java.util.logging etc.)
 */
public void log( String message ) {
    System.out.println( message );
}

/*
 * Better not to suppress exception usually
 */
public int addEntryRecordPS(String id) throws Exception {
    // using try with resources to delegate closing connection.
    try ( Connection con = getConnection() ) {
        long millis = System.currentTimeMillis();
        java.sql.Date date = new java.sql.Date(millis);
        Date today = new Date();
        Time currentTime = new java.sql.Time(today.getTime());
        try ( PreparedStatement checkPstm = con.prepareStatement( "SELECT id from Attend.EntryTable WHERE EntryTable.id = ? and EntryTable.DayOf = ?") ) {
            checkPstm.setString( 1 , id );
            checkPstm.setDate( 2 , date );
            try ( ResultSet rs = checkPstm.executeQuery() ) {
                boolean next = rs.next();
                log( "hasNext? : "+next );
                if ( next ) {
                    // again try with resource (no need to close pstm)
                    try ( PreparedStatement pstm = con.prepareStatement( "INSERT INTO Attend.ExitTable ( id, DayOf, TimeOf ) VALUES ( ?, ? ,? ) " )  ) {
                        pstm.setString( 1 , id );
                        pstm.setDate( 2 , date );
                        pstm.setTime( 3 , currentTime );
                        int res = pstm.executeUpdate();
                        log("Good job "+res);
                    }
                } else {
                    // again try with resource (no need to close pstm)
                    try ( PreparedStatement pstm = con.prepareStatement( "INSERT INTO Attend.EntryTable ( id, DayOf, TimeOf ) VALUES ( ?, ? ,? ) " )  ) {
                        pstm.setString( 1 , id );
                        pstm.setDate( 2 , date );
                        pstm.setTime( 3 , currentTime );
                        int res = pstm.executeUpdate();
                        log("Entry noted "+res);
                    }
                }
            }
        }
    }
    return 0;
}


Share : facebook icon twitter icon

Java code working on InventoryPart 2 program, have no idea what I am doing wrong?


By : user2972034
Date : March 29 2020, 07:55 AM
it fixes the issue As @Greg and @EboMike stated, make sure you split your code in two files: Television.java and InventoryPart2.java.
Then, you have a typo here:
code :
for (int i = 0; i < 5; i++){ //output total inventory value
    System.out.printf("Total Value of Inventory is: \t$%.2f\n", + myTelevision[i].getCalculateInventory());
    System.out.println();
}
    //output total inventory value
    double total = 0.0;
    for (int i = 0; i < 5; i++){ 
        total +=  myTelevisions[i].getCalculateInventory();            
    }
    System.out.printf("Total Value of Inventory is: \t$%.2f\n", total);

How do I "simplify" my Java code for a MySQL database program?


By : Fenil Parikh
Date : March 29 2020, 07:55 AM
will help you in a first step, you could use switch statement to handle menu inputs. create methods for connexion and for each input cases. add field to hold mysql connexion...
like
code :
switch(input){
    case 1:
        method1();
        break;
}
private static void method1(){
    //move code from input 1 here
}
 private static Connection mysql;
public class Main {

    private static Connection mysql;

    public static void main(String[] args) {
        connect();
        //...
    }

    private static void connect(){
            Class.forName("com.mysql.jdbc.Driver");
            String connectionStringURL = "jdbc:mysql://us-cdbr-azure-west-b.cleardb.com:3306/database";
            mysql = DriverManager.getConnection(connectionStringURL, "username", "password");
        if(mysql == null){
            System.out.println("Connection Failed");
        }else{
            System.out.println("Success");
        }
    }

//...

}

supersized jquery links colors not changing on slides heres my code.. Thankss in Advance


By : Hugo Martinez
Date : March 29 2020, 07:55 AM

My java program is not working, I ran the code and the sorting is not right


By : Yentis
Date : March 29 2020, 07:55 AM
help you fix your problem Here is the question from my instructor: , To sort by length, instead of
code :
if (arr[j].compareTo(arr[index]) < 0)
if (arr[j].length() < arr[index].length())

How to print only exit code ,when java program gives exception(running java program from shellscropt)?


By : HeBa YeHia
Date : March 29 2020, 07:55 AM
hop of those help? I have a java program which throws some exception,I tried executing it from shell script and printing 0 on failure and 1 on successful execution of java program.But It also printing the Exception onto console I just want to print exit code only.How to do this ?.Any suggestion are appreciated . , Try this.
Related Posts Related Posts :
  • After upgrading spring version getting java.lang.NoClassDefFoundError:
  • How to close application on onBackPressed() in home activity
  • NullPointerException while setting field in Test Class
  • Order of serialization in Java
  • Vaadin 14 Grid + Dialog: How to refresh grid after closing dialog?
  • finding words within String and returning as String + spaces Java
  • Negative Values when calculating time of a java date
  • when case switch between kernel mode and user mode for synchronized keyword in JAVA
  • Creating a repetitive action in a GUI without 'time drift'
  • Why Map api doesn't provide stream capabilities in Java?
  • Multi threaded issue with myMethod()
  • Is Java Synchronization required when loading data from another thread once?
  • Pass Multiple Keys in @Requestparam with a Single String Variable
  • PriorityQueue returning elements in wrong order
  • How to get sum of doubles in list using stream?
  • How to remove field from object conditionally, by other ENUM field value
  • MariaDB and flyway syntax error but not in JAVA
  • How to check in an array list if an item is immediately followed by another - Java
  • Class FIle has no arguments at the constructor
  • JavaFx 13 - TableView Vertical ScrollBar handler returns NullPointerException
  • Code crashes every time the helper class is executed
  • Java Problem- Null char prints no character on Mac OS but does print a blank space on Windows
  • Configuration of a Spring Data Repository class to hit read_replica_db for read/select methods and main_db for write/ins
  • Java PriorityQueue poll() order of values
  • Intiize the Custom object with empty string in java
  • Facing issue to handle more then two window with selenium webdriver
  • How to set connectTimeout in case of slow internet and if I don't know the size of file to download
  • Regular expression to remove the dot (.) from a number
  • Access shared folder from linux machine using java code
  • java code style: returning specific Map implementation when generic contract is not sufficient
  • Java function inside __groovy executes but the result is not being assigned to a variable
  • Decorating a concrete class, bad practice?
  • Copy table from Oracle to Redis
  • Moshi Multiple Custom Names
  • Create actual date in string format from microseconds with precision of microseconds
  • How to generate a spinner in Android with different background color in each item with Java?
  • Java8 variable in for loop
  • Why is my java code throwing an error when I get input from the user?
  • Why does Java's Stream.reduce method take an identity element instead of a default result?
  • Upload arraylist using httpurlconnection multipart/form-data
  • Java split() method can not distinguish "." and "-" on Windows
  • Java HashMap Did Not Return Expected Result when put the data
  • IBM MQ JMS java listener code keeping the program running
  • Java 'finally' clause in a nested 'try' block
  • How to call methods in functional interfaces without .Method()
  • how to make list of duplicates in custom arraylist Java
  • Safe publication of array/collection/map contents written once
  • How to set a new value (Date) for a Java bean property?
  • ExecutorService thread safety
  • StringBuilder - setLength(0) vs new instantiate, what is better?
  • Upgraded spring boot from 2.1.0 to 2.2.2.RELEASE , now getting exception while starting
  • Is it possible to find the original sequence of integers from its prefix sums and suffix sums?
  • How can I round up to 3 Decimal places in Java such that .000 shoould be there at the end of the value even if it is a s
  • What is the correct regex for a 24 hour clock with alphabet support (java)
  • Calculate next Birthday date given a birhdate?
  • Bean validation (JSR-303) errors not serialized with Spring DATA REST
  • Why my String is returning as a blank string?(JAVA)
  • How to read Json from online instead of asset folder
  • Java Error: illegal start of the expressions
  • Spring OAuth2 Authorization: Access Denied
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk