daily pastebin goal
47%
SHARE
TWEET

Untitled

a guest Feb 15th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.Statement;
  4. import java.sql.SQLException;
  5.  
  6. public class StringFormat {
  7.    
  8.     public static final String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver";
  9.     public static final String JDB_URL = "jdbc:mysql://localhost:3306/gces";
  10.  
  11.     public static void main(String[] args) {
  12.        
  13.         String insertQuery;
  14.         String name = "Hari KC", address = "Lamachaur";
  15.         float salary = 2345364;
  16.        
  17.         try {
  18.             insertQuery = String.format("INSERT INTO `employees` ( `username`, `address`, `salary`) VALUES ('%s', '%s', '%f')", name,address, salary);
  19.            
  20.             Class.forName(JDBC_DRIVER);
  21.             Connection conn = DriverManager.getConnection(JDB_URL,"root","");
  22.             Statement st = conn.createStatement();
  23.             st.executeUpdate(insertQuery);
  24.             st.close();    
  25.         }
  26.         catch(SQLException exc) {
  27.             exc.printStackTrace();
  28.         }
  29.         catch(ClassNotFoundException exc) {
  30.             exc.printStackTrace();
  31.         }
  32.        
  33.     }
  34.  
  35. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top