Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----
- // Create Point objects from the coordinate array
- Point[] points = new Point[coords.length];
- for (int i = 0; i<points.length; i++) {
- points[i] = new Point(coords[i][0], coords[i][1]);
- }
- someArray[][] = { {value, value}, {value, value}, {value, value} };
- ----
- ITTERATION
- int ar[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
- int x;
- // iterating over an array
- for (int i : ar) {
- // accessing each element of array
- x = i;
- System.out.print(x + " ");
- }
- https://stackoverflow.com/questions/11844012/they-say-in-java-every-thing-is-an-object-is-that-true
- resultSet.close();
- query.close();
- connection.close();
- ----
- package project;
- import java.sql.*;
- public class DatabaseConnection {
- private String dbUsername, dbPassword, dbHost, dbPort, dbName, dbUrl;
- private Connection dbConnection;
- public DatabaseConnection() throws ClassNotFoundException, SQLException {
- initComponents();
- }
- private void initComponents() throws ClassNotFoundException, SQLException {
- Class.forName("com.mysql.jdbc.Driver");
- this.dbUsername = "root";
- this.dbPassword = "root";
- this.dbHost = "localhost";
- this.dbPort = "3306";
- this.dbName = "test_my_database";
- this.dbUrl = "jdbc.mysql://" + this.dbHost + ":" + this.dbPort + "/" + this.dbName;
- this.dbConnection = DriverManager.getConnection(dbUrl, dbUsername, dbPassword);
- System.out.println("CONNECTION ESTABLISHED");
- }
- // public Connection getConnection() {
- //
- // }
- }
- ----
- package project;
- import java.sql.Connection;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- public class Project {
- public static void main(String[] args) {
- try {
- DatabaseConnection foo = new DatabaseConnection();
- Connection kook = foo.getConnection();
- Statement stat = foo.createStatement();
- ResultSet result = stat.executeQuery("select");
- while(result.next()) {
- int idusers = result.getInt("idusers");
- String name = result.getString("name");
- String email = result.getString("email");
- float value = result.getFloat("value");
- System.out.println(idusers + ": " + name + " at " + email + ". value: " + value);
- }
- }
- catch(ClassNotFoundException ex) {
- System.out.println("Driver not found");
- ex.printStackTrace(System.out);
- }
- catch(SQLException ex) {
- System.out.println("ERROR: Connection not established");
- ex.printStackTrace(System.out);
- }
- }
- }
- ----
- package project;
- import java.awt.BorderLayout;
- import java.awt.GridLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.*;
- public class FrameDataInsert extends JFrame {
- // behaviours
- private BorderLayout borderLayout;
- private GridLayout gridLayout;
- // frame
- private JLabel label;
- private JButton button;
- // panel
- private JPanel panel;
- private JTextArea username;
- private JTextArea password;
- private JTextArea value;
- public FrameDataInsert() {
- initComponents();
- this.setTitle("java.sql API testing");
- this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- this.pack();
- this.setVisible(true);
- }
- private void initComponents() {
- //behaviours
- gridLayout = new GridLayout(3,0);
- // frame
- label = new JLabel ("Insert data in fields, then press button");
- button = new JButton("insert");
- button.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent stim) {
- insertData();
- }
- });
- // panel
- panel = new JPanel(gridLayout);
- username = new JTextArea();
- password = new JTextArea();
- value = new JTextArea();
- // add
- this.add(label, BorderLayout.PAGE_START);
- this.add(button, BorderLayout.PAGE_END);
- this.add(panel, borderLayout.CENTER);
- panel.add(username);
- panel.add(password);
- panel.add(value);
- }
- private void insertData() {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement