Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- import java.io.*;
- public class harj21 {
- public static void main (String args[]) throws IOException {
- String Sqlkomento = "";
- String serverName = "localhost:3306";
- InputStreamReader converter = new InputStreamReader(System.in);
- BufferedReader in = new BufferedReader(converter);
- try {
- Class.forName("org.gjt.mm.mysql.Driver").newInstance();
- } catch (Exception E) {
- System.err.println("Unable to load.");
- E.printStackTrace();
- }try {
- String url = "jdbc:mysql://" + serverName + "/tol?user=aleksant&password=alluap";
- //KIRJAUTUMINE
- Connection MySQLcon = DriverManager.getConnection (url);
- Statement stmt = MySQLcon.createStatement ();
- // Tässä kirjoituskomento
- System.out.println("Anna select komento");
- Sqlkomento = in.readLine();
- ResultSet rs = stmt.executeQuery (Sqlkomento);
- while (rs.next()) {
- System.out.println ("");
- System.out.println ( + rs.getString(2));
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement