Advertisement
Stevenscott

Untitled

May 7th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.32 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package tcf;
  7. import java.sql.*;
  8. /**
  9.  *
  10.  * @author ScottJR
  11.  */
  12. public class Tcf {
  13.     private static final String USERNAME="root";
  14.     private static final String PASSWORD="scooter";
  15.     private static final String CONN_STRING=
  16.             "jdbc:mysql://localhost/Coach_info";
  17.     /**
  18.      * @param args the command line arguments
  19.      */
  20.     public static void main(String[] args) {
  21.  
  22.     Connection conn = null;
  23.    
  24.     try {
  25.         conn = DriverManager.getConnection(CONN_STRING,USERNAME,PASSWORD);
  26.         System.out.println("Connected!!");
  27.         Statement stmt = (Statement) conn.createStatement();
  28.         String Fname= "Shawn";
  29.         String Lname= "Scott";
  30.          String insert= "INSERT INTO basic_info(Fname, Lname, Location, Email, phone#)" +
  31.         "VALUES (?, ?, ?, ?, ?)";
  32.         PreparedStatement preparedStatement = conn.prepareStatement(insert);
  33.         preparedStatement.setString(1, "Steven");
  34.         preparedStatement.setString(2, "Spidey Scott");
  35.  
  36.         preparedStatement.executeUpdate();      
  37.     }catch(SQLException e){
  38.         System.err.println(e);
  39.     }
  40.                
  41.     }
  42.    
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement