Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: retrieving path coordinates from Mysql database to draw bezier curve on JFrame

  1. #1
    Junior Member
    Join Date
    Dec 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question retrieving path coordinates from Mysql database to draw bezier curve on JFrame

    I want to draw bezier cubic curves by retrieving data from MySQL database and then display the shape on JFrame
    I have table has 3 columns (ID, ObjectID, Points)
    Points column has coordinates of cubic curves, the statement i used
    SELECT * FROM DB.TABNAME WHERE OBJECTID=1;
    ObjectID=1 has 11 ID's, each ID contains a shape if i combine all ID`s together will form composite shape.
    How can i retrieve data from MySQL database, and then draw that shapes on the JFrame ?


  2. #2
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: retrieving path coordinates from Mysql database to draw bezier curve on JFrame

    Quote Originally Posted by aboyahia1435 View Post
    I have table has 3 columns (ID, ObjectID, Points)
    Points column has coordinates of cubic curves, the statement i used
    First, you should clarify what is, technically, the Points column (in other words, how those points are stored). Can you give an example?

    Quote Originally Posted by aboyahia1435 View Post
    I have table has 3 columns (ID, ObjectID, Points)
    SELECT * FROM DB.TABNAME WHERE OBJECTID=1;
    ObjectID=1 has 11 ID's, each ID contains a shape if i combine all ID`s together will form composite shape.
    How can i retrieve data from MySQL database, and then draw that shapes on the JFrame ?
    Using JDBC it's normal/common stuff: obtaining a Connection, creating a Statement (or PreparedStatement), execute the SQL query and then iterate over the ResultSet. And while doing this last thing, you can create GeneralPath objects you can then use to draw the shapes.

    What eventually (and at what level) are your doubts about JDBC?
    Andrea, www.andbin.net — SCJP 5 (91%) – SCWCD 5 (94%)

    Useful links for Java beginners – My new project Java Examples on Google Code

  3. #3
    Junior Member
    Join Date
    Dec 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: retrieving path coordinates from Mysql database to draw bezier curve on JFrame

    Well, The points are stored in data-type of MEDIUM-TEXT, these examples of the points (coordinates)
    458.41016 425.70843 427.74316 392.55343 403.93516 370.91243
    399.48516 366.83843 398.54916 368.02743 397.41516 372.27043
    394.75116 382.25643 392.96616 392.69543 391.09516 402.03043
    390.35916 405.62343 389.79116 406.92443 392.62616 409.52743
    406.00316 421.83343 442.19716 458.07143 444.89016 482.76843
    431.76716 528.31343 393.39116 574.56743 350.22516 594.56743
    316.63916 610.12643 278.88716 614.34043 242.18316 610.35243
    232.12112,609.27843 228.38012 619.29143 238.47016 621.92243
    274.01216 631.28543 320.32416 637.73643 356.57416 628.91043
    420.03416 613.46343 456.48216 533.71643 457.61616 470.82943
    all points have same Object-ID.
    So, my question is How can i create GeneralPath objects to draw the shapes, I know there's a method curveTo() used to Add a curved segment, defined by three new points, to the path by drawing a B้zier curve, and How can i use all these points(coordinates) to draw curve on JFrame and i have so many others i need to combine all of them together based on Object-ID's ?
    Thanks
    import java.sql.*;
     
    public class selectStmt {
    	private static final String DB_DRIVER = "com.mysql.jdbc.Driver";
    	private static final String DB_CONNECTION = "jdbc:mysql://127.0.0.1:3306/abo";
    	private static final String DB_USER = "username";
    	private static final String DB_PASSWORD = "pswd";
     
    	public selectStmt(){
    		try {
     
    			selectRecordsFromTable();
     
    		} catch (SQLException e) {
     
    			System.out.println(e.getMessage());
     
    		}
     
    	}
     
    	private static void selectRecordsFromTable() throws SQLException {
     
    		Connection dbConnection = null;
    		PreparedStatement preparedStatement = null;
     
    		String selectSQL = "SELECT * FROM abo.pathitems where ObjectID=1";
     
    		try {
    			dbConnection = getDBConnection();
    			preparedStatement = dbConnection.prepareStatement(selectSQL);
    			//preparedStatement.setInt(1, 100);
     
    			// execute select SQL stetement
    			ResultSet rs = preparedStatement.executeQuery();
     
    			while (rs.next()) {
     
    				/*   */
    			}
     
    		} catch (SQLException e) {
     
    			System.out.println(e.getMessage());
     
    		} finally {
     
    			if (preparedStatement != null) {
    				preparedStatement.close();
    			}
     
    			if (dbConnection != null) {
    				dbConnection.close();
    			}
     
    		}
     
    	}
     
    	private static Connection getDBConnection() {
     
    		Connection dbConnection = null;
     
    		try {
     
    			Class.forName(DB_DRIVER);
     
    		} catch (ClassNotFoundException e) {
     
    			System.out.println(e.getMessage());
     
    		}
     
    		try {
     
    			dbConnection = DriverManager.getConnection(
                                 DB_CONNECTION, DB_USER,DB_PASSWORD);
    			return dbConnection;
     
    		} catch (SQLException e) {
     
    			System.out.println(e.getMessage());
     
    		}
     
    		return dbConnection;
    	}
     
    }

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,361
    My Mood
    Mellow
    Thanks
    143
    Thanked 598 Times in 585 Posts

    Default Re: retrieving path coordinates from Mysql database to draw bezier curve on JFrame


  5. #5
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: retrieving path coordinates from Mysql database to draw bezier curve on JFrame

    Quote Originally Posted by aboyahia1435 View Post
    Well, The points are stored in data-type of MEDIUM-TEXT
    Ok, it's not really the most practical/easy way to store points in a DB but .... there are no particular problems, just some intermediate steps to do.

    1) Extracting the String value from the column:

    String values = rs.getString("points");

    2) Splitting the big string into many tokens. There are some possibilities, at least: split() of String or StringTokenizer.

    e.g.
    String[] valueTokens = values.split(" ");

    3) Each token must be converted to a float or, better, double value. Use parseDouble() of Double to do this.


    Now, at this point, there are various possibilities, depending on how you want to handle these values. And there is one question: in your other thread you have used:

    path.moveTo(457.61616,470.82943 );

    These 2 values seems the last two in the example you have posted. In other words, I don't know how all these values form points/curves. This is a thing you have to know (and eventually explain to us).
    Andrea, www.andbin.net — SCJP 5 (91%) – SCWCD 5 (94%)

    Useful links for Java beginners – My new project Java Examples on Google Code

  6. The Following User Says Thank You to andbin For This Useful Post:

    aboyahia1435 (December 12th, 2013)

  7. #6
    Junior Member
    Join Date
    Dec 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: retrieving path coordinates from Mysql database to draw bezier curve on JFrame

    Thanks andbin
    Well, I have a task to draw shapes beside each other based on Object-Id, these shapes are curves(Bezier Cubic Curve),they get those coordinates by using inkscape software to get vector graphics points(curves), to get that, the file wil be saved in .svg format which can open by any editor (such as notepad), this is an example of it
    HTML Code:
    <svg xmlns="http://www.w3.org/2000/svg" version="1.1">
    
      <path
         
         d="M 457.61616,470.82943 
    	 
    	 C 458.41016,425.70843 427.74316,392.55343 403.93516,370.91243 
    	 C 399.48516,366.83843 398.54916,368.02743 397.41516,372.27043 
    	 C 394.75116,382.25643 392.96616,392.69543 391.09516,402.03043 
    	 C 390.35916,405.62343 389.79116,406.92443 392.62616,409.52743 
    	 C 406.00316,421.83343 442.19716,458.07143 444.89016,482.76843 
    	 C 431.76716,528.31343 393.39116,574.56743 350.22516,594.56743 
    	 C 316.63916,610.12643 278.88716,614.34043 242.18316,610.35243 
    	 C 232.12112,609.27843 228.38012,619.29143 238.47016,621.92243 
    	 C 274.01216,631.28543 320.32416,637.73643 356.57416,628.91043 
    	 C 420.03416,613.46343 456.48216,533.71643 457.61616,470.82943" />
    </svg>
    Then they stored these coordinates in MySQL database (and all other coordinates)in data-type of MEDIUM-TEXT, like the above format.
    i hope my explanation to the matter is clear ?
    What the help i want how to retrieve these coordinates from MySQL database to draw shapes on JFrame ?

Similar Threads

  1. [SOLVED] Graphics Object Won't Draw To The Correct JFrame
    By NickNumero in forum AWT / Java Swing
    Replies: 7
    Last Post: October 27th, 2012, 01:07 PM
  2. Problem of retrieving pdf file from database using tomcat server
    By kalkumbenitin in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 26th, 2012, 06:16 AM
  3. getobject error retrieving data from mysql
    By zeberrun in forum Other Programming Languages
    Replies: 1
    Last Post: September 19th, 2011, 05:27 AM
  4. retrieving from database
    By zam in forum Threads
    Replies: 1
    Last Post: September 2nd, 2011, 06:22 PM
  5. MySQL Database
    By pjeremy90 in forum Java Theory & Questions
    Replies: 2
    Last Post: June 12th, 2010, 10:34 AM