Problem with Using JDBC in Applet

Hi,
i have written an applet to log in (it checks the database, if the username and pasword exists it shows corresponding message). i use access or sql server and applet is started but no message is shown(i think it does not connect to database). here is my code:
import javax.swing.*;
import java.sql.*;
import java.awt.event.*;
import java.awt.*;
public class appletDatabase extends JApplet implements ActionListener {
JLabel l1;
JLabel l2;
JLabel l3;
JTextField tf1;
JPasswordField tf2;
JButton btn;
Connection cn;
Statement st;
String hostname;
public void init() {
hostname = "localhost";
l1 = new JLabel("User Name: ");
l2 = new JLabel(" Password: ");
l3 = new JLabel(" ");
tf1 = new JTextField(20);
tf2 = new JPasswordField(20);
btn = new JButton("Sign in");
Container c = getContentPane();
c.setLayout(new FlowLayout(FlowLayout.LEFT));
c.add(l1);
c.add(tf1);
c.add(l2);
c.add(tf2);
c.add(btn);
c.add(l3);
btn.addActionListener(this);
setSize(300,300);
setVisible(true);
public void actionPerformed(ActionEvent e) {
if (e.getSource()==btn) {
boolean b = check(tf1.getText(),new String(tf2.getPassword()));
if (b) {
l3.setForeground(Color.green);
l3.setText("Username and password exists. ");
else {
l3.setForeground(Color.red);
l3.setText("Username and/or password does not exist.");
public boolean check(String un, String pass) {
String query="SELECT * FROM Table1 WHERE username LIKE'"+un+"'" +
" AND password LIKE'"+pass+"'";
boolean b = false;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
cn = DriverManager.getConnection("jdbc:odbc:login");
st = cn.createStatement();
ResultSet rs = st.executeQuery(query);
if (!(rs==null))
if (rs.next())
b = true;
rs.close();
st.close();
cn.close();
} catch (SQLException e1) {
e1.printStackTrace();
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
return b;
}

The first thing i notice is that there's a problem with your SQL statement.
To start with you should probably be using PreparedStatements cause it deals with the passing of variables very well and cleanly.
But if you must use a straight statement then it should be like this:
String query = "SELECT * FROM Table1 WHERE username LIKE '"+un+"'" + " AND password LIKE '"+pass+"'";
The fact that you were mising a few spaces wouldn't have helped. Although if you were to use a prepared statement, it would be a lot easier to understand where things were being passed and you don't need to worry about those single quotes for certain values.
Wes

Similar Messages

  • Beginner Has Problem With Loading JDBC Driver Using MySQL

    Hi, I am having problem with loading JDBC driver, and need your diagnotic help.
    1. I have installed MySQL (C:\mysql), created a databse (soup), and created a littel table (VIDEOS). I am able to see the table in the console:
    sql> select * from videos
    2. I have downloaded the latest version of Connector/J (mysql-connector-java-3.1.0-alpha.zip), and unzip the zip file into my C:\ directory.
    3. I copied the mysql-connector-java-3.1.0-alpha-bin.jar to the C:\j2sdk1.4.1_02\jre\lib\ext folder and it is in my CLASSPATH
    4. MySQL server is running
    C:\> C:\mysql\bin\mysqld-nt --standalone
    5. open another DOS window and use the database
    mysql>USE SOUP
    6. succesfully compiled a Java program (javac Test.java):
    import java.sql.* ;
    public class Test
    public static void main( String[] args )
    try
    Class.forName("org.gjt.mm.mysql.Driver").newInstance();
    try
    Connection con = DriverManager.getConnection( "jdbc:mysql://localhost:3306/soup" );
    try
    Statement statement = con.createStatement();
    ResultSet rs = statement.executeQuery("SELECT TITLE FROM VIDEOS");
    while ( rs.next() )
    System.out.println( rs.getString( "TITLE" ) );
    rs.close();
    statement.close();
    catch ( SQLException e )
    System.out.println( "JDBC error: " + e );
    finally
    con.close();
    catch( SQLException e )
    System.out.println( "could not get JDBC connection: " + e );
    catch( Exception e )
    System.out.println( "could not load JDBC driver: " + e );
    7. when I run the Java program (java Test), I got
    the message:
    could not load JDBC driver: java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver
    What am I missing?

    Hi,
    I missed to specify test in my last post.
    Try running your program by explicitly setting the classspath when
    running your program . java -classpath c:\mysql-connector-java-3.1.0-alpha-bin.jar test
    Make sure your jar file contains org.gjt.mm.mysql.Driver class

  • Language problem with my jdbc connection

    Hello,
    i'm having a problem with my jdbc connection.
    the problem is that i'm connecting to MS- Access db the have arabic tables, and columns, it was working fine on a windows XP environment prepared for arabic language, but when i had to move to windows vista it did not work and it gave me an exception.
    i'm using netbeans 6.1 IDE, and the exception is
    java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]COUNT field incorrect
    at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6957)
    at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7114)
    at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java:3110)
    at sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcStatement.java:338)
    when i printed the select statement and the exception it gave me:
    SELECT [??? ???????], [??? ??????], [??? ?????], [??? ?????], [????? ???????????] FROM EDU_DIVISION; [Microsoft][ODBC Microsoft Access Driver]COUNT field incorrect.
    the question marks are very weird to appear!!!!!!
    here is the code:
    public void edu_branch() {
            sucpy = 0;
            eflag = 0;
            asql = "SELECT [\u0643\u0648\u062F \u0627\u0644\u062C\u0627\u0645\u0639\u0629], [\u0643\u0648\u062F \u0627\u0644\u0643\u0644\u064A\u0629], [\u0643\u0648\u062F \u0627\u0644\u0642\u0633\u0645], [\u0643\u0648\u062F \u0627\u0644\u0634\u0639\u0628\u0629], [\u0627\u0633\u0645 \u0627\u0644\u0634\u0639\u0628\u0629], [\u0627\u0633\u0645 \u0627\u0644\u0634\u0639\u0628\u0629 \u0628\u0627\u0644\u0627\u0646\u062C\u0644\u064A\u0632\u064A\u0629], [\u0627\u0644\u0643\u0648\u062F \u0627\u0644\u0645\u062E\u062A\u0635\u0631] FROM EDU_BRANCH;";
            Connection connection;
            Statement statement;
            try {
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                connection = DriverManager.getConnection("jdbc:odbc:info");
                System.out.println("Connection to Access file is created...");
                statement = connection.createStatement();
                statement.execute(asql);
                System.out.println("Executing query : " + asql);
                aset = statement.getResultSet();
                if (aset != null) {
    //------------------------------Oracle operations--------------------------------------------------------------------                  
                    while (aset.next()) {
        can you help me please

    arabic language
    SELECT [??? ???????], [??? ??????], [??? ?????], [??? ?????], [????? ???????????] FROM EDU_DIVISION; >[Microsoft][ODBC Microsoft Access Driver]COUNT field incorrect.
    the question marks are very weird to appear!!!!!!It failed to understand your unicode sql.
    it was working fine on a windows XP environment prepared for arabic language, but when i had to move to windows vista it did not workStrange. Maybe you need to compare the differences of some system properties on both hosts, for instance, sun.io.unicode.encoding, file.encoding, user.region, and so on.

  • I am going to buy unlocked iphone 5.. i will be going to india nxt months and will stay there for a while... so my question is will i get warrenty in india.. and will there be any problem with using indian sims..?? thnx for the help..

    i am going to buy unlocked iphone 5.. i will be going to india nxt months and will stay there for a while... so my question is will i get warrenty in india.. and will there be any problem with using indian sims..?? thnx for the help..

    The warranty for the iPhone is not and has never been International.
    Warranty and support are ONLY valid in the country of origin.  The only exception is the EU where the entire EU is treated as one country.
    If the device will be used in India, buy it in India.
    An unlocked iPhone will work on any supported GSM carrier world wide.  The LTE portion of a US purchased, unlocked iPhone is unlikely to work outside North America as it does not support the appropriate bands used in other countries.

  • I have two Iphones with different email addresses sharing one Apple ID. Will that cause problems with using messaging and FaceTime?

    I have two Iphones 5 with different email addresses sharing one Apple ID account.Both are using IOS 8.
    I would like to set up a new Apple Id for one of the phones and remove it from the old account.
    If I do that, can I move all of the purchased apps and songs to the new Apple account?
    Also, will sharing one Apple ID account with two devices cause problems with using messaging and FaceTime?

    Sharing an iCloud account between two devices can be done without causing issues with iMessage and FaceTime, just go into Settings for each of these functions and designate separate points of contact (i.e. phone number only, or phone number and unique email address).  While that works, you'll then face the problem where a phone call to one iPhone will ring both if on the same Wi-Fi network -- but again, that can be avoided by changing each phone's settings.
    Rather than do all that, don't fight it -- use separate IDs for iCloud.  You can still use a common ID for iTunes purchases (the ID for purchases and iCloud do not have to be the same) or you can use Family Sharing to share purchases from a primary Apple account.

  • I purchased Adobe Creative Suite C2 and have been using it for years on the same computer no problem with using it. Recently upon opening Photoshop I received a pop up window saying due to Adobe Software security we need you to activate your CS2 software.

    I purchased Adobe Creative Suite C2 and have been using it for years on the same computer without any problems with using it. Recently upon opening Photoshop I received a pop up window saying due to Adobe Software security we need you to activate your CS2 software. I tried, phone activation, web activation, nothing is working. I have the serial number and my Adobe account information. Any suggestions?

    Error: Activation Server Unavailable | CS2, Acrobat 7, Audition 3
    Mylenium

  • Problem with use of COM+ Transaction and DB Transaction

    Problem with use of COM+ Transaction and DB Transaction
    We build a Web site that use sometime COM+ Transaction and sometime DB
    Transaction. If we use a COM+ Transaction and a few seconds later we try to use
    a Database Transaction (OracleConnection.BeginTransaction), we get the error
    Connection is already part of a local or a distributed transaction
    Of course the error does not produce everytime; it takes some try before we get
    the problem. And of course, if i use pooling=false on the connection string,
    the problem does not appear.
    i run the Web page
    and push the COM+ Transaction and DB Transaction one after the other for some
    times and the problem should appear.
    Environment: Windows server 2003, .Net Framework 1.1, ODP.Net 9.2.0.401,
    Database Server 9.2.0.4

    > Why in form builder can't I...
    Is this happening at runtime or at buildtime? You'll need to provide more info on what you are actually doing that's causing the problem.
    Regards,
    Robin Zimmermann
    Forms Product Management

  • Problems with use cases in JDeveloper 11.1.1.1.0

    Use cases made with JDeveloper 11.1.1.0.2 can not be used and edited in JDeveloper 11.1.1.1.0.
    Same problems with Use Case Diagrams.
    And it seems to be impossible to create new use cases in JDeveloper 11.1.1.1.0.
    What are the differences between 11.1.1.0.2 and 11.1.1.1.0 if you look at use cases??

    In JDeveloper 11.1.1.0.2 each use case has one file with the folllowing name: *.xhtml_usc.
    In JDeveloper 11.1.1.1.0 each use case has two files with a names like *.xhtml_usc and *.uml_usc (after standard migration with JDeveloper). I can still edit the *.xhtml_usc files, but I have no idea what to do with the *.uml_usc files. I can only open a Property-editor, but the properties I see have no relation with the text I used in my original use cases . New use cases only have a *.uml_usc file and a Property-editor. In javadoc the new use case does not appear.
    My question is: why do I have two different use case files in JDeveloper 11.1.1.0 and how can I use the Property editor??

  • AxWindowsMediaPlayer problem with using subtitle sami.file in winform

    Hello every body
    I have a problem with using sami caption in axWindowsMediaPlayer;
    how can I use it?
    I used
    axWindowsMediaPlayer1.closedCaption.SAMIFileName="FileNameAddress";
    and
    axWindowsMediaPlayer1.ShowPropertyPages();//and select sami file
    but in both ways the subtitle is not shown in my axWindowsMediaPlayer1 control;
    please help me for solving this problem

    Hi ,
    As i know the Synchronized Accessible Media Interchange (SAMI) file must use an .smi or .sami file name extension.
    set the smi-file direclty like following
    AxWindowsMediaPlayer.closedCaption.SAMIFileName = "subtitles.smi";
    Please also refer here
    for more details.
    Follow the steps below for your Windows Media Player to display captions and subtitles.
    http://support.3playmedia.com/entries/21934486-windows-media-files-windows-media-player-settings
    Related thread, please note the Style secttion.
    http://answers.microsoft.com/en-us/windows/forum/windows_7-pictures/wmp-12-doesnt-play-sami-files-closed-captions/96fe98b7-1cdf-41f5-aa9e-a4e55fd07c0a
    In addition, Could you please provide your smi or sami file and full code? It could be better to help us do some test on my side.
    Have a nice day!
    Kristin
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • I am having problem with using the Basic brush definition

    I am having problem with using the Basic brush definition. When I try to click on it will not allow me to use it and will automatically use the 5 pt. oval brush definition. The only way I can use the basic brush is after I have already drawn something and then I have to click on the stroke and then press basic. This is incredibly annoying and if anyone could help I would greatly appreciate it. (I have Adobe CS6)

    for whatever reason, the basic 'brush' you see in the brushes palette effectively means removing any brush from a path. to draw with the brush tool you need a brush defined. in your case the last one selected being the 5 pt oval one.

  • I am having problem with using my Basic brush definition

    I am having problem with using the Basic brush definition. When I try to click on it will not allow me to use it and will automatically use the 5 pt. oval brush definition. The only way I can use the basic brush is after I have already drawn something and then I have to click on the stroke and then press basic. This is incredibly annoying and if anyone could help I would greatly appreciate it. (I have Adobe CS6)

    Basic is not a brush, only a starting point for you to make a brush. Load the real brush you want before beginning to draw.

  • In FF4.0.1 problem with using HTML creator in WebCT. WHY? Not a problem in FF4.0.0

    In FF4.0.1 problem with using HTML creator in WebCT. WHY? Not a problem in FF4.0.0

    Hi Shane,
    I passed through all the described problems in the list, and after doing several tests the error that you described is always present if the "jpcsclite_en_US.properties" is not present in the same place of the "jpcsclite.properties". I really don't know the reason, I just copied and pasted the same file, renamed the copy and the error was gone... though both of them include the line where the .dll is found!
    That's how it worked for me, but if anybody knows how it works without that dirty trick, it would be good.
    Regards,
    Leandro
    PS: Just in case that somebody is using the version JCSDK3.0, I did not find the .dll in that version, but in the JCSDK2.2.2 *(:-S)*

  • I have a problem with using MacBook Pro as wifi router when connected to ethernet

    I have a problem with using MacBook Pro as wifi router when connected to ethernet. The Airport icon changes to show a laptop inside, my iPad shows connected (I think) but Safari will not operate. I tried pinging my iPad, it seems to see the iPad, but no connection to Safari or to other apps such as Good on the iPad. I have read many posting and tried repeatedly via Sharing in Systems Preferences, but no luck. Suggestions to fix, or is this a Lion problem?

    Usually this is a problem related to the domain name server address. If you open Network preferences, select your Ethernet port then click on the Advanced button then on the DNS tab. You will likely see an entry like 10.0.1.1 already listed. Click on the Add [-] button and enter 208.67.222.222 then click on the OK button and then on the Apply button.  See if this helps.
    if it does not help then repeat the above but with the Airport port.

  • After installing Snow Leopard problems with using any of my Helvetica fonts

    I've never really have a problem with any of apple's products until now.
    After installing Snow Leopard I've found problems with using any of my Helvetica fonts,
    which is a BIG problem if you work in DTP or print. You CAN'T remove the system version of Helvetica, and replace it with your own anymore.
    Also Flash CS4 seems to be a dead duck, as after about 5-6 seconds of loading the program it crashes with a "KERNPROTECTIONFAILURE".
    <title edited by host>

    Thanks Tom but the original post title was "Work in DTP, don't install snow leopard", but of course apple were unhappy with the title. I know the issue/problem has been discussed for months, the real problem is that it shouldn't be a problem which everyone has to find work arounds for.
    After 4 days of playing about, I've finally got flash CS4 working and Quarkxpress was also a big problem for a few months. Printer description (PPD) files which snow leopard doesn't like, but worked in tiger & leopard.....means I can't use my two A3 inkjets for proofing anymore.
    I'm just disappointed by snow leopard

  • I have a problem with using (hotmail)

    i have a problem with using (hotmail) , that when i try to use messenger through it , that shown many of pages can not be open , and my contacts are not available , when i contact with Windows Live team to solve the problem they inform me that the problem is with my browser , so i have to ask them about it , and i use Mozilla Firefox 8.0 , so kindly help me to solve this issue

    That is a problem with Silverlight
    On a Mac, Firefox 4 is a 64 bit application.<br />
    Not all plugins support 64 bit and if not then you need to start Firefox in 32 bit mode to use that plugin.
    # Close Firefox
    # Start the Finder and open the Applications folder
    # Right click or control-click the Firefox.app icon
    # Select "Get Info"
    # Select or Deselect "Open in 32-bit mode"
    # Close the "Firefox Info" window
    # Restart Firefox

Maybe you are looking for