📄 tryplaceholders.java
字号:
import java.sql.*;
public class TryPlaceHolders
{
public static void main(String[] args)
{
try
{
String url = "jdbc:odbc:technical_library";
String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String user = "guest";
String password = "guest";
Class.forName(driver);
Connection connection = DriverManager.getConnection(url);
String changeLastName = "UPDATE authors SET lastname = ? WHERE authid = ?";
PreparedStatement updateLastName = connection.prepareStatement(changeLastName);
updateLastName.setString(1,"Booooob"); // Set lastname placeholder value
updateLastName.setInt(2,27); // Set author ID placeholder value
int rowsUpdated = updateLastName.executeUpdate(); // execute the update
System.out.println("Rows affected: " + rowsUpdated);
connection.close();
}
catch (ClassNotFoundException cnfe)
{
System.err.println(cnfe);
}
catch (SQLException sqle)
{
System.err.println(sqle);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -