Advertisement
Guest User

Untitled

a guest
Jul 17th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.04 KB | None | 0 0
  1. import java.sql.*;
  2. import java.io.*;
  3.       public class harj21 {
  4.       public static void main (String args[]) throws IOException {
  5.       String Sqlkomento = "";
  6.       String serverName = "localhost:3306";
  7.       InputStreamReader converter = new InputStreamReader(System.in);
  8.       BufferedReader in = new BufferedReader(converter);
  9.  
  10.  try {
  11. Class.forName("org.gjt.mm.mysql.Driver").newInstance();
  12. } catch (Exception E) {
  13.       System.err.println("Unable to load.");
  14.       E.printStackTrace();
  15. }try {
  16.     String url = "jdbc:mysql://" + serverName + "/tol?user=aleksant&password=alluap";
  17.     //KIRJAUTUMINE
  18.     Connection MySQLcon = DriverManager.getConnection (url);
  19.     Statement stmt = MySQLcon.createStatement ();
  20. // Tässä kirjoituskomento
  21.  
  22.     System.out.println("Anna select komento");
  23.     Sqlkomento = in.readLine();
  24.     ResultSet rs = stmt.executeQuery (Sqlkomento);
  25.  
  26.  
  27.   while (rs.next()) {
  28.       System.out.println ("");
  29.       System.out.println ( + rs.getString(2));
  30.      
  31. }
  32. } catch (SQLException e) {
  33. e.printStackTrace();
  34. }
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement