Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class Main {
    public static void main(String[] args) throws Exception {
        System.out.println("Inserting values in  database table!");
        Connection con = null;
        String url = "jdbc:jtds:sqlserver://127.0.0.1:1433/Example";
        String username = "sa";
        String password = "";
        String driver = "net.sourceforge.jtds.jdbc.Driver";
        Class.forName(driver);
        con = DriverManager.getConnection(url, username, password);
        Statement st = con.createStatement();
        int val = st.executeUpdate("insert into dbo.Company " + "values('abc', 2)");
        System.out.println("1 row affected");
    }
}