Is this code need to be enhanced further? If yes,please give your inputs

Hai Coders,
The code below is a part of a java file for authentication. Its working version. I want to know how can i write optimized code for authentication of username and password. Comment on my code how can I improve it.
Is it up to Standard ( up to good java programmer )
Is it possible to optimize my coder further?
Any other alternatives that works better than this code for authentication?
As a java Programmer rate my code(1 to 10)..
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:srcname","","");
Statement stmt=con.createStatement();
String str1="";//username & assume that getting input from user
String str2="";//password & assume that getting input from user
ResultSet rs=stmt.executeQuery("select * from tablename");
while(rs.next()) {
String s1=rs.getString(8);
String s2=rs.getString(1);
if((s1.equals(str1))&&(s2.equals(str2))) {           
System.out.println("Success");
} catch(Exception e) {
System.out.println("Fail");
}

Friends My new updated code,
Give comments to improve my code further,
package javaapplication1;
import java.sql.*;
* @author m.senthil kumar
public class Main {
public static void main(String[] yahoo) {
Connection con=null;
PreparedStatement pstmt=null;
ResultSet rs=null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:tecch", "uuu", "ppp");
String userName = "jav1a";//username & assume that getting input from user
String password = "java";//password & assume that getting input from user
pstmt = con.prepareStatement("select username from test where username=? and password=?");
pstmt.setString(1, userName);
pstmt.setString(2, password);
rs = pstmt.executeQuery();
boolean b = false;
while (rs.next()) {
b = true;
break;
if (b) {
System.out.print("Success");
} else {
throw new unauthorized();
} catch (Exception e) {
System.out.print(e);
} finally {
try{
if(rs!=null)
rs.close();
if (pstmt != null) {
pstmt.close();
if (con != null) {
con.close();
catch(Exception e)
System.out.print(e);
class unauthorized extends Exception {
public String toString() {
return "You are not authorized person";
}

Similar Messages

  • What is the error code mean? And how to solve it ?Please give your answer. Thanks

    What is the error code  mean? And how to solve it ?Please give your answer. Thanks
    Attachments:
    QQ截图20140403134626.png ‏59 KB

    duplicate post
    LabVIEW Champion . Do more with less code and in less time .

  • Redemption code from Photoshop Elements 12 purchased from Best Buy does not work 'Oops! This code doesn't seem to be active. Please contact the retailer you purchased the card from, or use a different code.'   I have an invoice and the pickup notice from

    Redemption code from Photoshop Elements 12 purchased from Best Buy does not work 'Oops! This code doesn't seem to be active. Please contact the retailer you purchased the card from, or use a different code.'   I have an invoice and the pickup notice from Best Buy.   What other information does Best Buy need?   What will they do?   Will I get a new box?   What happened to the days of just typing in a simple s/n?   

    Redemption Code Help
    http://helpx.adobe.com/x-productkb/global/redemption-code-help.html

  • When I give the redeem code from the package I bought today from over an hour away, this is what i get and no forun seems to deal with it nor do I have days to chase adobe down.  Oops! This code doesn't seem to be active. Please contact the retailer you p

    When I give the redeem code from the package I bought today from over an hour away, this is what i get and no forun seems to deal with it nor do I have days to chase adobe down. Oops! This code doesn't seem to be active. Please contact the retailer you purchased the card from, or use a different code. For more information contact Customer Support and order by phone

    See if this helps:
    https://helpx.adobe.com/x-productkb/global/find-serial-number.html

  • Quickly!Quickly!Quickly!What is the error code mean? And how to solve it ?Please give your answer. Thanks

    What is the error code mean? Why is there an error?And how to solve it ?Please give your answer. Thanks!                                               
    ——1110340026
    Attachments:
    QQ图片20140403140655.jpg ‏108 KB

    Sannieboyyyy wrote:
    Could be me, but your VI is not working properly on the english version of LV. Can I suggest you to try programming in English in the future?
    Yes, it's you. The VI is working just fine, except for some cosmetic issues with the labeling. I don't think is is a valid suggestion to force somebody to program in a specific language, especially since LabVIEW supports all these languages.
    Here are the problems with the VI:
    If you don't want an amplitude of zero, you need to set the amplitude control to a nonzero value before running. Simple as that!. (You could also set the input range for the amplitude control to exclude zero or use a case structure to skip certain code if the amplitude is zero).
    You could also wire the error output to an indicator so it simply displays the errors, but keeps running.
    Your while loop is currently useless. You can delete it and the program function will not change. Use a stop button at the loop condition.
    Your while loop needs some timing so it runs at a reasonable rate. Either add a small wait or configure the signal generation to "simulate acquisition timing" instead of "run as fast as possible".
    LabVIEW Champion . Do more with less code and in less time .

  • Is Apple providing any karaoke service such as selling karaoke software, whole set of karaoke hardware or even karaoke store? If yes, please give me information on this; If no, let me know if there are similar karaoke services providing in the future.

    Is Apple providing any karaoke service such as selling karaoke software, whole set of karaoke hardware or even karaoke store? If yes, please give me information on this; If no, let me know if there are similar karaoke services providing in the future.

    No, Apple does not. What other companies might provide what you're looking for I don't know. Try searching the web for "karaoke software" or something similar.
    Regards.

  • Cannot get on iMessage or FaceTime I get this message "FaceTime Activation: Could not sign in.  Please check your network connection and try again

    Cannot get on iMessage or FaceTime I get this message "FaceTime Activation: Could not sign in.  Please check your network connection and try again

    Try something really simple.
    Restart the iPad by holding down on the sleep button until the red slider appears and then slide to shut off. To power up hold the sleep button until the Apple logo appears and let go of the button.
    Or try this. Reboot the iPad by holding down on the sleep and home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider if it appears on the screen - let go of the buttons. Let the iPad start up.
    Or try this as well. Go to Settings>General>Date and Time>Set Automatically>On. Make sure it is set to On.
    @Freckles888 ..... I really doubt that "millions of others" are having this problem. I think that news would be all over the airwaves and Apple would be taking more heat about it that we can imagine.

  • What files does this code need?

    I am trying to use this code from Java Examples In A Nutshell.
    It is a short program that involves reading one and writing to another (I think!) The way I understand things is that there has to be two files for the program to be able to run, from_file & to_file . I have attempted to creat two txt files and saved them as these names in the same folder as the app. The code complies as you would expect, when I try to run it I get Usage: FileCopy <source> <destination> and the app never runs. I suspect I have not created the external files properly. If you can see where I have gone wrong let me know, layman's terms please, Dave.

    When running the compiled "FileCopy.class" with java command you must enter the names of files, i.e.;
    java FileCopy "from_file" "to_file"
    in the command line.
    In this case args[0] is "from_file" and args[1] is "to_file."

  • Do this code need to have BufferedInputStream?

    Good day, Java Guru!
    Here is my code:
    BufferedInputStream inputStream = new BufferedInputStream(connection.getInputStream());
    ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
    byte[] result = new byte[128];
    int totalBytes;
    while((totalBytes = inputStream.read(result)) != -1) {
           byteOutput.write(result, 0, totalBytes);
    }Variable connection represents opened Socket connection which returns to us input stream with bytes.
    Will it be effective to have BufferedInputStream while reading bytes if my approach also use byte[128] array to read them?

    The default size for the buffer in BufferedInputStream is 4096. So, by using it in this code you will save 31 out of every 32 physical reads to the socket, i.e. 31/32 system calls, context switches, ... I believe you will find that it is beneficial. On the other hand if you were to use a bugger byte array, such as 4096 or more, you would find the BufferedInputStream to be a cost.
    But as the other poster suggested you could have tested and measured this for yourself.
    BTW it is rarely a good idea to read an entire socket stream into memory unless you know in advance that it's not very large. Consider what will happen if it's a multi-gigabyte movie. It's generally best to put it somewhere piece by piece, or parse it piece by piece as it comes in.

  • What is code needed to check user fill in? Please help!

    Hi all,
    I need to check the data that users fill in (in multi record block) so that it is increasing number. For example:
    100000
    100001
    100003
    100010
    100011
    I want to put this code at Post-Item trigger so that an alert will flash the moment users finished entering an item and it is less number than previous_item. How do I achieve this in Form 6i?
    Thanks in advance for any tip.

    have a form level parameter.
    Put the value of the first field into this parameter in its post item.
    in the next item post item just check if its value is larger then the parameter. if it is set the parameter to its new value.

  • What files does this code need part II?

    This is a continuation of a question asked earlier today http://forum.java.sun.com/thread.jsp?forum=54&thread=321833 . I now have been able to run this app & it seems okay. But I am confused as I expected the to_file to be overwritten by the from_file.
    However when I check text files they appear to be the same as they were at first. Why? Dave.

    Try again after deleting the "to_file" or use another name for the output file.

  • I   just  got  a  new iPone 4S and  would  like  to  change  my ringtone  to  an  Allen  Jackson  song .  I  already  download iTunes . I'm  very  new  to this  and  need  help ????..please

    I just  got  a  new iPhone 4S . I  would  like  to  change my  ringtone to an Alan Jackson  song .  I already download i Tunes .  but  i don't  know  how  to  do it . i'm  very  new  to this  and  would  like to know if someone  can help me with this ? Thanks

    Your past purchases are not on the computer.   By choosing download all, those purchases will download to the computer. 
    Once authorized to your iTunes account you can control the computer.
    When syncing the iPad the first time you will get the warning " this iPad is synced with another computer, syncing will erase all contents and replace with the contents of this computer"
    Say yes, this is what you wan to do. 

  • I am designing successive approximation ADC designed using LabVIEW I need DAC digital to analog converter block please give me DAC code

    help me

    Hi,
    To send your boolean array bit by bit you'll have to enter your array in a For Loop to unindex it.
    You could use your counter output, if there's any, to generate the clock for the D/A, if not, you'll have to make it programatically.
    Dario Camargo
    NI Brazil
    #1197019

  • Can you help me with the WHERE clause? Any issue with this code block?

    Hi,
    I am looking for blogs or any document on how to implement a Lookup during data loads in BW.
    The problem is that all those that I find on this site are mostly about u201CLookup in XIu201D
    I have read bits and hints on different postings on this site and this is the best I could do for the scenario shown below:
    I need to add the Chars: Char1, Char2, Char3 to CubeX
    so that I can display the data for these 3 Chars in a report.
    Char1 and Char2 are filled in ODS12 and Char3 is filled in Cube3.
    Can you help me write a routine so that while loading data to CubeX, it will read Char1, Char2, Char3 from ODS12 and Cube3; and make them available in CubeX?
    This is my attempt so far:   continue:
    u201C----
    select /bic/Char1 from /bic/ODS12
    select /bic/Char2 from /bic/ODS12
    select /bic/Char3 from /bic/Cube3
    into result
    WHERE u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026
    and objvers = 'A' .        
    end select.
    u201C----
    1. What should be my WHERE clause?
    2. In the select statement, by studying samples on this where should there be an u201CMu201D in front of the ODS? e.g. select /bic/Char1 from /bic/MODS12
    If so, what is the significance and the other options?
    3. Should this code be in the Start routing of CubeX? Or any other possible location? Also, in the start routine does it matter where within the start routine this code needs to be placed?
    4. Can you please fix this code and add any lines I may be missing?
    Is what I am looking to do refer to as u201Cdoing a lookupu201D?
    Thanks

    ok

  • How to make this code go faster?

    Hi,
    I have this code and its really slow. My question is how to make it faster since its taking about 10 hours.
    Code:
      loop at ti_equi.
        select matnr sernr lief_nr kunde datum uzeit bwart posnr
    appending corresponding fields of table ti_ser01
          from z_objk_ser01
         where sernr eq ti_equi-sernr
           and matnr eq ti_equi-matnr.
      endloop.
      delete ti_ser01 where not ( kunde in s_kunnr and
                                  bwart = '631' ).
      sort ti_ser01 by matnr sernr datum descending uzeit descending.
      delete adjacent duplicates from ti_ser01 comparing matnr sernr.
    What this code does is fetch all these fields and then just keeps the one that's been modified at last.
    I have created an index by sernr and matnr in table objk which makes it just a little bit faster.
    Any helpful answer will be appreciated.
    Regards,
    Roberto
    Edited by: Julius Bussche on Jan 27, 2009 4:29 PM
    Code tags added. Please use more meaningfull subject titles

    Hi roberto
    please avoid select statment inside loop.
    use code
    data: index type sy-tabix.
    data : ti-ser011 type standard table of zobjk-ser01 with header line.
    select matnr sernr lief_nr kunde datum uzeit bwart posnr
          from z_objk_ser01 into table ti_ser01.
    sort ti_ser01 by sernr matnr.
    sort ti_equi by sernr matnr.
    index = 1.
    loop at ti_equi.
        loop at ti_ser01 from index
         if  ti_ser01-sernr = ti_equi-sernr
              and ti_ser01-matnr = ti_equi-matnr.
            move-corresponding ti_ser01 to ti_ser011.
            append ti_ser011.
            index = sy-tabix.
            exit.  
         endif.
        endloop.
    endloop.
    here i have used one more internal table ti_ser011.
    you can delete specific record from ti_ser01 internal table on condition. at that time u don't need to create any other internal table like ti-ser011.
    in place of loop select statement---endloop.
    you can use this code. I think it will help you.
    please find if it is udeful.

Maybe you are looking for

  • Multiple directories in rtmp

    I have hard time getting this URL to work on FMS 3.0.1 and latest Flash player. rtmp://localhost/vod/flv:Catalog/userA/sample.flv If I move the sample.flv to the Catalog directory, it works fine (rtmp://localhost/vod/flv:Catalog/sample.flv). I've tri

  • Status 29 in ALe Idocs

    Hi All, Recently I've come across a problem in ALE Idoc. The status of the idoc is 29 Error in ALE service. This kind of error is encountered when there is a configuration problem in either Partner profiles or Port definitions. The Partner profile is

  • Exception in thread "main" java.lang.UnsupportedClassversion error.

    hi, I am having the JDk and jre versions in C: drive i am jdk version 1.5.0 but when i am running the command version it is showing 1.4.2_03 version and also i am having the oracle 10g on my system. tried seeting classpath also but no success. I am t

  • How to email generated HTML report

    Can I create a link on my generated report that will issue the mailto command and email the results of this report run?

  • Garbled "underwater" distortion in itunes

    If i leave itunes on for a while, then the music it plays starts to sound like it is under water... there is this strange sound distortion. It is not resolved by closing Itunes and re opening and is only resolved when i reset my computer. Usually itu