//adding label and textfields to panel panel2 panel2.setLayout(new GridLayout(3,1)); //setting line and titled border for panel panel2 panel2.setBorder(BorderFactory.createLineBorder(Color.red)); panel2.setBorder(BorderFactory.createTitledBorder("Enter Your Information!")); panel2.add(lblname); panel2.add(jtext1); panel2.add(lbladd); panel2.add(jtext2); //adding panel to container this.getContentPane().add(panel2,"Center"); this.getContentPane().add(psouth,"South"); this.setSize(400,300); this.setLocation(100,200); this.show(); }
public static void main(String args[]){ AwtDatabase ad = new AwtDatabase(); }
//event handling public void actionPerformed(ActionEvent e){ if(e.getSource()==btnok) { PreparedStatement pstm; ResultSet rs; String sql; if((jtext1.getText().equals("")&&(jtext2.getText().equals("")))) { lblmsg.setText("Enter your Name & RollNo."); lblmsg.setForeground(Color.magenta); }
else{
try{ Connection con = null; String url = "jdbc:mysql://192.168.10.211:3306/"; String db = "amar"; String driver = "com.mysql.jdbc.Driver"; String userName ="amar"; String password="amar123"; //loading the driver Class.forName(driver); con = DriverManager.getConnection(url+db,userName,password); pstm=con.prepareStatement("insert into student_detail values(?,?)"); pstm.setString(1,jtext1.getText()); pstm.setString(2,jtext2.getText()); //execute method to execute the query pstm.executeUpdate(); lblmsg.setText("Details have been added to database");
//closing the prepared statement and connection object pstm.close(); con.close(); } catch(SQLException sqe) { System.out.println("SQl error"); } catch(ClassNotFoundException cnf) { System.out.println("Class not found error"); } } } if(e.getSource()==btnaddnew) { jtext1.setText(""); jtext2.setText(""); } if(e.getSource()==btnexit){ System.exit(1); } } }
August 14, 2008 at 8:04 PM
And use for MS-Access database
Step for using this example.
* go to ms-access and make a table and give it a file name student.mdb * go to Control Panel * click on Administrative Tools, click on ODBC(win98) * click on ODBC * Then , you will see a ODbc dialog box.click on UserDSn * click on add button * Select microsoft Access Driver(*.mdb) driver and click on finish * give a data Source name (table name) * Then click on Select * Browse on the database name you have created and click it:student.mdb is a database file where all data will be stored
java
java hi im new to java plz suggest me how to master java....saifjunaid@gmail.com
java java How to set java Policy for applet using jdk 6
java
java dear,
i want a field for date picker using java/java script
java
java create java program for delete and update the details,without using database, just a normal java program
java
java why methods in java raise exceptions
Have a look at the following link:
Java Exceptions
java java code to search the nodes how to write the java code to search the nodes using routers
java java online telephone directory i need coding for online telephone directory..by using java....pls help me
java
java how to edit text document by using java
then how to edit starting and ending of text document by using java
java
java different between java & core java
print("code sample
java
java different between java & core java
print("code sample
java java pattern code for a given words java pattern code for a given words pattern
java
java how can use sleep in java
which book learn of java language
java
java how to prepare the java
Hi Friend,
If you want to learn how to install java, creating and running a java program then go through the following links:
http://www.roseindia.net/java/beginners/index.shtml
http
java
java java swing
Swing is a principal GUI toolkit for the Java programming language. It is a part of the JFC (Java Foundation Classes), which is an API for providing a graphical user interface for Java programs
java
java what is the need of java if java is not there what will happen... work unless you have Java installed, and more are created every day. Java... to scientific supercomputers, cell phones to the Internet, Java is everywhere!
http
java
java 1.what type of inheritance supported in java.
2.what is the advantage of java over C++.
Hi Friend,
Java supports following... inheritance
Advantages of Java over C++:
1)Java is pure object oriented
java
java how to run applets in java
Hi,
In Java you can use Applet viewer to run the applet. Read more at Java Applet Viewer tutorial page.
Thanks
java
java what is javaJava is a programming language..., and business applications.
Advantages of Java:
* Java is simple, easy to design... programming languages.
* Java is object-oriented, that is used to build modular
Java Java What is the immediate superclass of the Dialog class