Compile and then run the following Java code sample.
import java.sql.*;
public class SQL2K5 {
public static void main(String[] args) throws SQLException
{
try
{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection conn =
DriverManager.getConnection("jdbc:sqlserver://<Server>:1433;DatabaseName=<DatabaseName>","<UserId>","<Password>");
Statement stmt = conn.createStatement();
try { stmt.executeUpdate("drop table t_Repro748"); } catch(Exception ignored) {}
stmt.executeUpdate("create table t_Repro748(col1 varchar(50), col2 int)");
stmt.executeUpdate("insert into t_Repro748(col1,col2) values('This test has failed!',1)");
PreparedStatement pstmt = conn.prepareStatement("update t_Repro748 set col1 = 'This test''s succeeded!',col2=?");
pstmt.setInt(1, 3);
pstmt.executeUpdate();
ResultSet rs = stmt.executeQuery("select * from t_Repro748");
while (rs.next())
System.out.println(rs.getString(1));
rs.close();
stmt.executeUpdate("drop table t_Repro748");
stmt.close();
conn.close();
}
catch(Exception e)
{
System.out.println(e);
e.printStackTrace();
}
}
}