⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tryinputstream2.java

📁 非常好的java事例以及带源码事例的java2教程
💻 JAVA
字号:
import java.sql.*;
import java.io.*;

public class TryInputStream2
{
  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);

      // Create a statement object and execute a SELECT
      Statement getCode = connection.createStatement();
      ResultSet theCode = getCode.executeQuery(
                                 "SELECT name,source FROM source_code");
      BufferedReader reader;                         // Reader for a column
      String input;                                  // Stores an input line

      while(theCode.next())                          // For each row
      {
        // Create a buffered reader from the stream for a column
        reader = new BufferedReader(
                                new InputStreamReader(theCode.getAsciiStream(2)));

        // Read the column data from the buffered reader
        while((input = reader.readLine()) != null)   // While there is a line
          System.out.println(input);                 // display it
      }


      connection.close();
    }
    catch (Exception e)
    {
      System.err.println(e);
    }
  }
}

⌨️ 快捷键说明

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