Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package sqlModifier;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileReader;
- import java.io.IOException;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.SQLException;
- public class ModifierMain {
- public static void main(String[] args) {
- Connection dbConn=connect();
- try {
- PreparedStatement psmt=dbConn.prepareStatement(InputStencyl("dbCMDs/insert.sql"));
- psmt.setString(1, "Sponge Bob");
- psmt.setInt(2, 34);
- psmt.setDouble(3,12.56);
- psmt.executeUpdate();
- System.out.println("good");
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- public static String InputStencyl(String fileName){
- File f=new File(fileName);
- try(
- FileReader fr=new FileReader(f);
- BufferedReader bfr=new BufferedReader(fr);
- ){
- String stencyl="";
- while(true){
- String in=bfr.readLine();
- if(in==null){
- return stencyl;
- }
- else{
- stencyl+=in;
- };
- }
- }catch(IOException IOE){
- IOE.printStackTrace();
- return "failed";
- }
- }
- public static Connection connect(){
- try {
- Connection c=DriverManager.getConnection("jdbc:mysql://127.0.0.1/course?&useSSL=true&useUnicode=true","root","mysqlFRS");
- return c;
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- return null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement