0% found this document useful (0 votes)
3 views1 page

Java JDBC and Swing Code Examples

The document contains two Java code snippets. The first snippet demonstrates how to connect to a MySQL database and execute a query to retrieve student data, while the second snippet illustrates a simple Swing application that displays a window with the text 'Hello Swing!'. Both snippets serve as examples of Java programming for database interaction and GUI creation.

Uploaded by

m.madhav0708
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Java JDBC and Swing Code Examples

The document contains two Java code snippets. The first snippet demonstrates how to connect to a MySQL database and execute a query to retrieve student data, while the second snippet illustrates a simple Swing application that displays a window with the text 'Hello Swing!'. Both snippets serve as examples of Java programming for database interaction and GUI creation.

Uploaded by

m.madhav0708
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Java Code Snippet 1:

import [Link].*;

public class JDBCExample {


public static void main(String[] args) {
try {
[Link]("[Link]");

Connection con = [Link](


"jdbc:mysql://localhost:3306/testdb", "root", "password");

Statement stmt = [Link]();


ResultSet rs = [Link]("SELECT * FROM students");

while ([Link]());

[Link]();
} catch (Exception e) {
[Link]("[Link]");
[Link]("[Link]");
}
}
}

Java Code Snippet 2:


import [Link].*;
import [Link].*;

public class HelloSwing extends JPanel {

@Override
public void paintComponent(Graphics g) {
[Link](g);
[Link]("Hello Swing!", 50, 50);
}

public static void main(String[] args) {


JFrame frame = new JFrame("Hello Swing Example");
HelloSwing panel = new HelloSwing();

[Link](panel);
[Link](300, 150);
[Link](JFrame.EXIT_ON_CLOSE);
[Link](true);
}
}

You might also like