I am trying to insert some data into my database using java and sql 2008 express and so i've downloaded the jar files I nedd from Download: Microsoft JDBC Driver 4.0 for SQL Server - Microsoft Download Center - Download Details and I went to my project and clicked on "Run">>>"Run Configurations">>>"CLASSPATH" >>>"Add External Jars" and I added the jar file RunConfigurations.jpg
my code is as follows:
import java.sql.*; public class Insertme { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub try { /* String url = "jdbc:msql://200.210.220.1:1114/Demo"; */ String url = "jdbc:sqljdbc4://WEIGHBRIDGE2-PC/sqlexpress/NewDB"; Connection conn = DriverManager.getConnection(url,"",""); Statement st = conn.createStatement(); /* st.executeUpdate("INSERT INTO MyNames " + "VALUES (Talent, 'Simpson')"); */ st.executeUpdate("INSERT INTO MyNames VALUES ('Talent', 'Simpson')"); conn.close(); } catch (Exception e) { System.err.println("Got an exception! "); e.printStackTrace(); /*System.err.println(e.getMessage()); */ } } }