Advertisement
Guest User

Untitled

a guest
Apr 18th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.54 KB | None | 0 0
  1. import java.sql.*;
  2. import java.util.Scanner;
  3.  
  4.  
  5. public class Main {
  6.  
  7.         static String daneZBazy;
  8.         /**
  9.          * @param args
  10.          */
  11.         public static void main(String[] args) {
  12.             for(;;){
  13.                 System.out.print("Wpisz polecenie: ");
  14.                 String wpisane;
  15.                 Scanner odczyt = new Scanner(System.in);
  16.                 wpisane = odczyt.nextLine();
  17.                 String polaczenieURL = "jdbc:mysql://teolight.win/coreboxp_db?user=coreboxp_toor&password=E3IR4qio4T";
  18.                 String query = "INSERT INTO wiadomosci (nick, wiadomosc) VALUES (nick, wiadomosc)";
  19.                 Connection conn = null;
  20.                
  21.                 try {
  22.  
  23.                        
  24.                         conn = DriverManager.getConnection(polaczenieURL);
  25.                        
  26.                      
  27.                         Class.forName("com.mysql.jdbc.Driver");
  28.                        
  29.                        
  30.                         Statement stmt = conn.prepareStatement(query);
  31.                         //ResultSet rs = stmt.executeQuery(query);
  32.                         stmt.executeUpdate(query);
  33.        
  34.                         //while (rs.next()) {
  35.                           //     wyswietlDaneZBazy(rs);
  36.                         //}
  37.        
  38.                         conn.close();
  39.                 }
  40.                
  41.                 catch(ClassNotFoundException wyjatek) {
  42.                         System.out.println("Problem ze sterownikiem");
  43.                 }
  44.  
  45.                 catch(SQLException wyjatek) {
  46.                         //e.printStackTrace();
  47.                         //System.out.println("Problem z logowaniem\nProsze sprawdzic:\n nazwę użytkownika, hasło, nazwę bazy danych lub adres IP serwera");
  48.                         System.out.println("SQLException: " + wyjatek.getMessage());
  49.                     System.out.println("SQLState: " + wyjatek.getSQLState());
  50.                     System.out.println("VendorError: " + wyjatek.getErrorCode());
  51.                 }
  52.         }
  53.         }
  54.         static void wyswietlDaneZBazy(ResultSet rs){
  55.                 try{
  56.                 daneZBazy = rs.getString(1);
  57.                 System.out.println("\n" + daneZBazy + " ");
  58.                 daneZBazy = rs.getString(2);
  59.                 System.out.println(daneZBazy + " ");
  60.                 daneZBazy = rs.getString(3);
  61.                 System.out.println(daneZBazy);
  62.                 }catch(SQLException e) {
  63.                         e.printStackTrace();
  64.                 }
  65.         }
  66.                
  67.  
  68.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement