Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package utk;
- import java.sql.*;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- public class JDBC {
- public static String[] pytanie = new String[40];
- public static int[] id = new int[40];
- public static int[] poprawna = new int[40];
- public static int[] nrTestu = new int[40];
- public static String[] odpA = new String[40];
- public static String[] odpB = new String[40];
- public static String[] odpC = new String[40];
- public static String[] odpD = new String[40];
- public static String[] zdjecie = new String[40];
- public static String[] kategoria = new String[40];
- public static int i = 0;
- public static void polacz() {
- String polaczenieURL = "jdbc:mysql://192.168.2.51/UTK";
- String user = "root";
- String passwd = "zaq1@WSX";
- String query = "Select * FROM odpowiedzi";
- Connection conn = null;
- try {
- conn = DriverManager.getConnection(polaczenieURL, user, passwd);
- Class.forName("com.mysql.jdbc.Driver");
- Statement stmt = conn.createStatement();
- ResultSet rs = stmt.executeQuery(query);
- while (rs.next() && i < 40) {
- pobierz40(rs, i);
- i++;
- }
- conn.close();
- }
- catch (ClassNotFoundException wyjatek) {
- System.out.println("Problem ze sterownikiem");
- }
- catch (SQLException wyjatek) {
- System.out.println("SQLException: " + wyjatek.getMessage());
- System.out.println("SQLState: " + wyjatek.getSQLState());
- System.out.println("VendorError: " + wyjatek.getErrorCode());
- }
- }
- static void pobierz40(ResultSet rs, int i) {
- try {
- id[i] = rs.getInt(1);
- pytanie[i] = rs.getString(2);
- odpA[i] = rs.getString(3);
- odpB[i] = rs.getString(4);
- odpC[i] = rs.getString(5);
- odpD[i] = rs.getString(6);
- poprawna[i] = rs.getInt(7);
- nrTestu[i] = rs.getInt(8);
- zdjecie[i] = rs.getString(9);
- kategoria[i] = rs.getString(10);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement