Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package eksemepel;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- public class SkriveTilFil {
- public static Connection getConnection() throws SQLException {
- return DriverManager.getConnection("jdbc:sqlserver://Dennis\\DENNIS;databaseName=Banksystem;user=sa;password=helloWorld;");
- }
- public static Statement getStatement() throws SQLException {
- return SkriveTilFil.getConnection().createStatement();
- }
- public static String getFraKonto(int kontoNr) throws SQLException {
- boolean findes = false;
- String gemString = null;
- ResultSet res = SkriveTilFil.getStatement().executeQuery("Select Saldo from Konto where Konto.ktoNr = " + kontoNr);
- gemString = res.getString(1);
- if (gemString == null){
- System.out.println("intet at komme efter");
- } else {
- System.out.println("Der er data");
- }
- return gemString;
- }
- public static String getTilKonto(int kontoNr) throws SQLException {
- boolean findes = false;
- String gemString = null;
- ResultSet res = SkriveTilFil.getStatement().executeQuery("Select Saldo from Konto where Konto.ktoNr = " + kontoNr);
- gemString = res.getString(1);
- if (gemString == null){
- System.out.println("intet at komme efter");
- } else {
- System.out.println("Der er data");
- }
- return gemString;
- }
- public static void main(String[] args) throws SQLException {
- SkriveTilFil.getTilKonto(1234567);
- }
- }
Add Comment
Please, Sign In to add comment