Tagged: mysql Toggle Comment Threads | Keyboard Shortcuts

  • CG 7:17 pm on November 6, 2012 Permalink | Reply
    Tags: inserting variable into table, , mysql, PreparedStatement, ResultSet   

    Inserting into MySQL Table 

    Here’s how to get result from a table using ResultSet and use it as variables to be inserted to another table using PreparedStatement

    
    import java.sql.*;
    import java.sql.DriverManager;
    import java.sql.Connection;
    import com.mysql.jdbc.Driver;
    import java.net.*;
    import java.io.*;
    public class CountUser{
    public static void main(String args[]) {
    try{
    Class.forName("com.mysql.jdbc.Driver");
    // Connection connection = DriverManager.getConnection("jdbc:mysql://167.205.24.50/table","root","");
    Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/table","root","");
    Statement st1 = connection.createStatement();
    Statement st2 = connection.createStatement();
    
    ResultSet rs1 = st1.executeQuery("SELECT * FROM user");
    
    while (rs1.next()) {
    java.sql.Date date = rs1.getDate(5);
    String strDate = date.toString();
    
    PreparedStatement ps = connection.prepareStatement("INSERT INTO count_temp (no, date) VALUES (?,?)");
    ps.setInt(1, i);
    ps.setString(2, strDate);
    ps.executeUpdate();
    }
    }
    catch (Exception e){
    System.out.println("Error: " + e);
    }
    }
    }
    
     
  • CG 9:34 am on July 22, 2010 Permalink | Reply
    Tags: mysql, PHP, XAMPP   

    XAMPP for Mac 

    1. Download XAMPP here
    2. Install XAMPP by clicking the .dmg file
    3. Start the Apache, MySQL and FTP Server
    4. You can put your Websites in /Applications/XAMPP/htdocs/ and access them via http://localhost/
    5. Or you put your Websites in the Sites-Folder in your Home and access them via http://localhost/~yourname/
    6. Type your first php code and save it in /Users/yourname/Sites
    7. Access it via browser http://localhost/~yourname/helloworld.php

     
    • Bobby 3:51 pm on July 24, 2010 Permalink | Reply

      berlanjut aja ke php framework belajarnya

      • CG 10:24 pm on July 24, 2010 Permalink | Reply

        bob, text editor cukup ringan dan flexibel di mac itu TextMate ya?

        • Bobby 8:51 am on July 25, 2010 Permalink

          iyah, kelebihannya di snippetnya. btw kok tumben belajar php?

        • CG 9:00 am on July 25, 2010 Permalink

          musti nyiapin infrastruktur php mysql di mac buat ngajar 🙂

  • CG 12:45 pm on December 9, 2009 Permalink | Reply
    Tags: , mysql   

    Connecting java with mysql on mac os 10.5 

    1. Install MySQL downloaded from here (choose one appropriate with your mac os 10.5)
    2. Install JDBC Connecter downloaded from here. Extract the file and find “mysql-connector-java-5.1-bin.jar”. Copy the file to “library/java/extension”
    3. Compile this code to make sure that the connection works well
    import java.sql.*;
    public class connect{
       public static void main(String argv[]) throws Exception {
    
       Class.forName("com.mysql.jdbc.Driver");
    
       Connection conn = DriverManager.getConnection(
       "jdbc:mysql://localhost:3306/test",
       "root",
       "rahasia"
     );
    
     Statement stmt = conn.createStatement();
     ResultSet rset = stmt.executeQuery("SELECT now();");
    
     while (rset.next()) {
     System.out.println(rset.getString(1));
     }
    
     rset.close();
     stmt.close();
     conn.close();
     }
     }
    
    

    Notes: thanks for tutorial here.

    Useful links:

    1. http://www.wbluhm.com/MySQLTut.html
    2. http://www.pantz.org/software/mysql/mysqlcommands.html
    3. http://webdosen.bl.ac.id/dosen/050023/materi/koneksi_java_mysql.pdf
    4. http://www.kitebird.com/articles/jdbc.html
     
  • CG 12:56 am on December 8, 2009 Permalink | Reply
    Tags: , mysql   

    Teaching preparation 

    The phd student is distracted from finishing the Koblitz curve equation coding, and doing some mysql and connecting it to java. Will get back to the research A.S.A.P.

     
    • Budi Rahardjo 5:32 pm on December 10, 2009 Permalink | Reply

      We need the Kobliz to be done ASAP!
      Can you do it this week?
      We need progress.

      • CG 10:19 pm on December 10, 2009 Permalink | Reply

        working on it 🙂

c
Compose new post
j
Next post/Next comment
k
Previous post/Previous comment
r
Reply
e
Edit
o
Show/Hide comments
t
Go to top
l
Go to login
h
Show/Hide help
shift + esc
Cancel