EXP Computer ThinConnect4 Guide de l'utilisateur Page 151

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 163
  • Table des matières
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 150
// You need to import the java.sql package to use JDBC
import java.sql.*;
// We import java.io to be able to read from the command line
import java.io.*;
class my_app
{
static BufferedReader in;
public static void main(String args[])
throws SQLException, IOException, Exception
{
String driverConStr = "jdbc:rdbThin://555.1.14.91:1888/";
in = new BufferedReader(new InputStreamReader(System.in));
Class.forName ("oracle.rdb.jdbc.rdbThin.Driver");
{
// Prompt the user for connect information
System.out.println(
"Please enter information to test connection"+
" to the database");
String user;
String password;
String database;
user = readEntry("user: ");
int slash_index = user.indexOf('/');
if (slash_index != -1)
password = user.substring(slash_index + 1);
user = user.substring(0, slash_index);
}
else
password = readEntry("password: ");
database = readEntry("database: ");
System.out.print("Connecting to the database...");
System.out.flush();
System.out.println("Connecting...");
Connection conn = DriverManager.getConnection(
driverConStr + database, user, password);
System.out.println("connected.");
// Create a statement
Statement stmt = conn.createStatement();
// Do the SQL "Hello World" thing
ResultSet rset = stmt.executeQuery(
"select 'Hello World' from rdb$database");
while (rset.next())
System.out.println(rset.getString(1));
// close the result set, the statement and connect
rset.close();
stmt.close();
conn.close();
}
151
Vue de la page 150
1 2 ... 146 147 148 149 150 151 152 153 154 155 156 ... 162 163

Commentaires sur ces manuels

Pas de commentaire