Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package javaapplication8;
- /**
- *
- * @author Student
- */import java.sql.*;
- public class Konekcija {
- public static void main(String[] args)
- {
- try
- {
- String dbUrl="jdbc:mysql://localhost:3309/itsbaza";
- String user= "root";
- String pass= "";
- Class.forName("com.mysql.jdbc.Driver");
- Connection veza= DriverManager.getConnection(dbUrl,user,pass);
- Statement st=veza.createStatement();
- String upit="select * from studentnovi";
- try {
- ResultSet rezultat=st.executeQuery(upit);
- System.out.println("Ispravljacki program (drajver) je ucitan!");
- while(rezultat.next())
- {
- System.out.println(rezultat.getString("ime")+ " " +
- rezultat.getString("prezime") + " " +rezultat.getString("BrojIndeksa")
- + " " +rezultat.getString("smer"));
- };
- String upit2="INSERT into studentnovi(BrojIndeksa,ime,prezime,smer) VALUES (?,?,?,?)";
- PreparedStatement pstate= veza.prepareStatement(upit2);
- pstate.setString(1, new String("123"));
- pstate.setString(2, new String("Pera"));
- pstate.setString(3, new String("PEric"));
- pstate.setString(4, new String("Mata"));
- try {
- pstate.executeUpdate();
- } catch (SQLException e) {
- System.out.println("Izuzetak. " + e);
- }
- } catch (Exception e) {
- System.out.println("Pogresan upit");
- }
- }
- catch ( SQLException ex)
- {
- System.out.println("Izuzetak. " + ex);
- }
- catch ( ClassNotFoundException e)
- {
- System.out.println("Upravljacki program nije caitan." + e);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement