Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to draw points with coordinates from database

 
Karol Dziedzic
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would be grateful for some examples.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65115
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Draw points where? In a browser? On a Swing app window?

Please TellTheDetails, and tell us exactly what part has you puzzled.
 
Karol Dziedzic
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I extracted columns from database and made calculations inside while loop. I know i need to make array to get from it coordinates for points. I want to draw them in interface created in another class but i have black hole and don't know how to get datas from while loop to array which is below.
 
Swastik Dey
Rancher
Posts: 1625
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Show us some code, i.e. what you have done so far.
 
Karol Dziedzic
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.sql.*; import java.util.ArrayList; import javax.swing.*;

public class punkty { String serverName = ?; String database = ?; String user = ?; String password = ?; String JDBC= "com.mysql.jdbc.Driver"; String url = ?; public static void main(String[] args) throws SQLException, ClassNotFoundException {

Connection connection = DriverManager.getConnection(url, user, password); Statement s = null; Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); s = connection.createStatement();

String sql = "SELECT a, b ,c ,d FROM db"; ResultSet rs = s.executeQuery(sql); float a1,a2,b1,b2; float x,y; while(rs.next()){ a1 = rs.getFloat("a"); a2 = rs.getFloat("b"); x=a1+a2; // result: group of x points b1 = rs.getFloat("c"); b2 = rs.getFloat("d"); y=b1+b2; // result: group of y points

// What was the problem: // This code is working well but I dont know how to get values from while loop to make below steps

// Pn(xn,yn) - there is that many points as many probes // number of probes is changing very fast // I want to create array with x and y values // Using array create points which I will represent in existing interface created in another class (on button click) } } }
 
Piet Souris
Rancher
Pie
Posts: 1314
29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Karol,

on this address you can find a complete demo of a scatter plot, including explanation:

http://math.hws.edu/javanotes/c13/s4.html

see section 13.4.3.

Greetz,
Piet
 
Karol Dziedzic
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Many thanks;) I will check it;)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic