Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- import java.util.Scanner;
- public class Main {
- static String daneZBazy;
- /**
- * @param args
- */
- public static void main(String[] args) {
- for(;;){
- System.out.print("Wpisz polecenie: ");
- String wpisane;
- Scanner odczyt = new Scanner(System.in);
- wpisane = odczyt.nextLine();
- String polaczenieURL = "jdbc:mysql://teolight.win/coreboxp_db?user=coreboxp_toor&password=E3IR4qio4T";
- String query = "INSERT INTO wiadomosci (nick, wiadomosc) VALUES (nick, wiadomosc)";
- Connection conn = null;
- try {
- conn = DriverManager.getConnection(polaczenieURL);
- Class.forName("com.mysql.jdbc.Driver");
- Statement stmt = conn.prepareStatement(query);
- //ResultSet rs = stmt.executeQuery(query);
- stmt.executeUpdate(query);
- //while (rs.next()) {
- // wyswietlDaneZBazy(rs);
- //}
- conn.close();
- }
- catch(ClassNotFoundException wyjatek) {
- System.out.println("Problem ze sterownikiem");
- }
- catch(SQLException wyjatek) {
- //e.printStackTrace();
- //System.out.println("Problem z logowaniem\nProsze sprawdzic:\n nazwę użytkownika, hasło, nazwę bazy danych lub adres IP serwera");
- System.out.println("SQLException: " + wyjatek.getMessage());
- System.out.println("SQLState: " + wyjatek.getSQLState());
- System.out.println("VendorError: " + wyjatek.getErrorCode());
- }
- }
- }
- static void wyswietlDaneZBazy(ResultSet rs){
- try{
- daneZBazy = rs.getString(1);
- System.out.println("\n" + daneZBazy + " ");
- daneZBazy = rs.getString(2);
- System.out.println(daneZBazy + " ");
- daneZBazy = rs.getString(3);
- System.out.println(daneZBazy);
- }catch(SQLException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement