Myjdbc. Java

Source: Internet
Author: User

Import javax. Swing. swingutilities;
Import java. AWT. borderlayout;

Import javax. Swing. jcomponent;
Import javax. Swing. joptionpane;
Import javax. Swing. jpanel;
Import javax. Swing. jframe;
Import javax. Swing. jlabel;

Import java. AWT. headlessexception;
Import java. AWT. rectangle;
Import java. AWT. dimension;
Import java. AWT. Font;
Import java. SQL. connection;
Import java. SQL. drivermanager;
Import java. SQL. preparedstatement;
Import java. SQL. resultset;
Import java. SQL. sqlexception;

Import javax. Swing. jtextfield;
Import javax. Swing. jbutton;

Public class myjdbc extends jframe {

Private Static final long serialversionuid = 1l;

Private jpanel jcontentpane = NULL;

Private jlabel = NULL;

Private jlabel jlabel1 = NULL;

Private jtextfield = NULL;

Private jtextfield jtextfield1 = NULL;

Private jbutton = NULL;

Private jbutton jbutton1 = NULL;

Public static int I = 0;
Public static myjdbc single = NULL;

/**
* This method initializes jtextfield
*
* @ Return javax. Swing. jtextfield
*/
Private jtextfield getjtextfield (){
If (jtextfield = NULL ){
Jtextfield = new jtextfield ();
Jtextfield. setbounds (New rectangle (199, 21,151, 54 ));
Jtextfield. sethorizontalalignment (jtextfield. center );
Jtextfield. settext ("");
Jtextfield. setfont (new font ("dialog", Font. Plain, 18 ));
}
Return jtextfield;
}

/**
* This method initializes jtextfield1
*
* @ Return javax. Swing. jtextfield
*/
Private jtextfield getjtextfield1 (){
If (jtextfield1 = NULL ){
Jtextfield1 = new jtextfield ();
Jtextfield1.setbounds (New rectangle (199, 90,151, 54 ));
Jtextfield1.sethorizontalalignment (jtextfield. center );
Jtextfield1.setfont (new font ("dialog", Font. Plain, 18 ));
}
Return jtextfield1;
}

/**
* This method initializes jbutton
*
* @ Return javax. Swing. jbutton
*/
Private jbutton getjbutton (){
If (jbutton = NULL ){
Jbutton = new jbutton ();
Jbutton. setbounds (New rectangle (37,162, 97, 48 ));
Jbutton. setfont (new font ("dialog", Font. Bold, 24 ));
Jbutton. settext ("OK ");
Jbutton. addactionlistener (New java. AWT. event. actionlistener (){
Public void actionreceivmed (Java. AWT. event. actionevent e ){

// String uid = jtextfield. gettext ();
// String upass = jtextfield1.gettext ();
// Try {
// Class. forname ("oracle. JDBC. Driver. oracledriver ");
// Connection conn = drivermanager. getconnection ("JDBC: oracle: thin: Scott/tiger @ localhost: 1522: stuf1dbsid ");
//
/// SQL
// String SQL = "select * from login where sname = '" + uid + "' and pass = '" + upass + "'";
/// Result
// Preparedstatement psmt = conn. preparestatement (SQL );
// Resultset res = psmt.exe cutequery ();
// If (res. Next ())
//{
// System. Out. println (res. getstring (1 ));
// System. Out. println (res. getstring (2 ));
// Res. getstring (1 );
// System. Out. println ("Login OK ");
// Joptionpane. showmessagedialog (null, "Login successful ");
//
/// Testdia T = new testdia (null );
/// T. setvisible (true );
//} Else
//{
// System. Out. println ("Login error ");
// Joptionpane. showmessagedialog (null, "Logon Failed ");
//
//}
//} Catch (classnotfoundexception E1 ){
//// Todo logs? When else catch?
// E1.printstacktrace ();
//}
//
// Catch (sqlexception E1 ){
//// Todo logs? When else catch?
// E1.printstacktrace ();
//}
//
//
String uid = jtextfield. gettext ();
String upass = jtextfield1.gettext ();
// String flag = "0 ";
// Flag = testdb. Connect (UID, upass );
//
// If (flag. Equals ("1 "))
//
//{
/// System. Out. println ("Login OK ");
/// Joptionpane. showmessagedialog (null, "Login successful ");
//
//
// Search T = new search ();
//
// T. setvisible (true );
//
// Single. setvisible (false );


Dbconnected. Connect ();



String SQL = "select * from login where sname = '" + uid + "' and pass = '" + upass + "'";
Resultset res = dbconnected. getmsg (SQL );


Try {
If (res. Next ())

{
// Joptionpane. showmessagedialog (null, "Login successful ");


Search T = new search ();


T. setvisible (true );

Single. setvisible (false );


}






Else

{System. Out. println ("Login 4 ");
Joptionpane. showmessagedialog (null, "Logon Failed ");}
} Catch (headlessexception E1 ){
// Todo auto-generated Catch Block
E1.printstacktrace ();
} Catch (sqlexception E1 ){
// Todo auto-generated Catch Block
E1.printstacktrace ();
}




























//
/// System. Out. println ("actionreceivmed ()");
// String name = jtextfield. gettext ();
// String pass = jtextfield1.gettext ();
// String url = "JDBC: oracle: thin: Scott/tiger @ localhost: 1522: stuf1dbsid ";
// Try {
// Class. forname ("oracle. JDBC. Driver. oracledriver ");
//} Catch (classnotfoundexception E1 ){
/// Todo auto-generated Catch Block
// E1.printstacktrace ();
//}
// Try {
// Connection conn = drivermanager. getconnection (URL );
// String SQL = "select * from login where sname = '" + name + "' and" + "Pass = '" + pass + "'";
// Preparedstatement psmt = conn. preparestatement (SQL );
// Resultset res = psmt.exe cutequery ();
// If (res. Next ())
//{
// System. Out. println (res. getstring (1 ));
// System. Out. println (res. getstring (2 ));
// Res. getstring (1 );
/// System. Out. println ("Login OK ");
/// Testdia T = new testdia (null );
/// T. setvisible (true );
// System. Out. println ("Login OK ");
// Joptionpane. showmessagedialog (null, "Login successful ");
//} Else
//{
// System. Out. println ("Login error ");
// Joptionpane. showmessagedialog (null, "Logon Failed ");
//}
//} Catch (sqlexception E1 ){
/// Todo auto-generated Catch Block
// E1.printstacktrace ();
//}
//

}});
}
Return jbutton;
}

/**
* This method initializes jbutton1
*
* @ Return javax. Swing. jbutton
*/
Private jbutton getjbutton1 (){
If (jbutton1 = NULL ){
Jbutton1 = new jbutton ();
Jbutton1.setbounds (New rectangle (236,163, 93, 49 ));
Jbutton1.setfont (new font ("dialog", Font. Bold, 24 ));
Jbutton1.settext ("reset ");
Jbutton1.addactionlistener (New java. AWT. event. actionlistener (){
Public void actionreceivmed (Java. AWT. event. actionevent e ){
System. Out. println ("actionreceivmed ()");
Jtextfield. settext ("");
Jtextfield1.settext ("");

}
});
}
Return jbutton1;
}

/**
* @ Param ARGs
*/
Public static void main (string [] ARGs ){
// Todo auto-generated method stub
Swingutilities. invokelater (New runnable (){
Public void run (){
Myjdbc thisclass = new myjdbc ();
Single = thisclass;
Thisclass. setdefaclocloseoperation (jframe. exit_on_close );
Thisclass. setvisible (true );


}
});
}

/**
* This is the default constructor
*/
Public myjdbc (){
Super ();
Initialize ();
}

/**
* This method initializes this
*
* @ Return void
*/
Private void initialize (){
This. setsize (405,261 );
This. setcontentpane (getjcontentpane ());
This. settitle ("jframe ");
}

/**
* This method initializes jcontentpane
*
* @ Return javax. Swing. jpanel
*/
Private jpanel getjcontentpane (){
If (jcontentpane = NULL ){
Jlabel1 = new jlabel ();
Jlabel1.setbounds (New rectangle (36, 87,103, 55 ));
Jlabel1.setfont (new font ("dialog", Font. Bold, 18 ));
Jlabel1.settext ("password ");
Jlabel = new jlabel ();
Jlabel. setbounds (New rectangle (36, 23,103, 50 ));
Jlabel. setfont (new font ("dialog", Font. Bold, 18 ));
Jlabel. settext ("User Name ");
Jcontentpane = new jpanel ();
Jcontentpane. setlayout (null );
Jcontentpane. Add (jlabel, null );
Jcontentpane. Add (jlabel1, null );
Jcontentpane. Add (getjtextfield (), null );
Jcontentpane. Add (getjtextfield1 (), null );
Jcontentpane. Add (getjbutton (), null );
Jcontentpane. Add (getjbutton1 (), null );
}
Return jcontentpane;
}

} // @ Jve: Decl-Index = 0: Visual-constraint = "125, 18"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.