tryinputstream.java

来自「Java Classic Examples是我买的两本书:《JAVA经典实例》和」· Java 代码 · 共 43 行

JAVA
43
字号
import java.sql.*;
import java.io.*;

public class TryInputStream
{
  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";

      FileInputStream fis = new FileInputStream("TryInputStream.java");

      Class.forName(driver);
      Connection connection = DriverManager.getConnection(url, user, password);
      Statement createTable = connection.createStatement();

      // Execute the SQL to create the table
      createTable.executeUpdate(
                  "CREATE TABLE source_code (name CHAR(20), source LONGTEXT)");

      // Create a PreparedStatement to INSERT a row in the table
      String ins = "INSERT INTO source_code VALUES(?,?)";
      PreparedStatement statement = connection.prepareStatement(ins);

      // Set values for the placeholders
      statement.setString(1, "TryInputStream");              // Set first field
      statement.setAsciiStream(2, fis, fis.available());     // Stream is source

      int rowsUpdated = statement.executeUpdate();
      System.out.println("Rows affected: " + rowsUpdated);
      connection.close();
    }
    catch (Exception e)
    {
      System.err.println(e);
    }
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?