Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static Connection getNewDBConnection() {
- System.out.println("************************Inside Get DB Connection**************************");
- Properties props = new Properties();
- if (connection != null)
- try {
- if (!connection.isClosed())
- return connection;
- } catch (SQLException e) {
- e.printStackTrace();
- }
- try {
- String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
- String url = "jdbc:sqlserver://142.168.0.112:1733;DatabaseName=OrganizationMasterDB";
- String user = "sa";
- String password = "Dsdf@123";
- Class.forName(driver);
- connection = DriverManager.getConnection(url, user, password);
- if (!connection.isClosed())
- System.out.println("---------------------DB Connection is Established----------------------");
- } catch (ClassNotFoundException e) {
- System.out.println("Class Not Found Exception Thrown ");
- e.printStackTrace();
- } catch (SQLException e) {
- System.out.println("SQL Exception Thrown");
- e.printStackTrace();
- }
- return connection;
- }
- public static void insertDetailsList(PersonalLedger pl) {
- Connection conn = getNewDBConnection();
- PreparedStatement statement = null;
- DetailsList dl = null;
- int temp=0,shareAmount=0,shareBalance=0,theiftFundAmount=0,theiftFundInterest=0,GAmtDepo=0,GInterest=0,ShareWithdrawn=0;
- String EmNo=null,MemberNo=null, fundString = "Share",status="Unknown",remarks="OtherAmount for Share is The Withdrawn Share Amount",sql=null;
- boolean flag= false;
- Date sdate = pl.SDate,gdate=pl.Gdate,tdate=pl.TDate;
- EmNo = pl.EmNo;
- MemberNo = pl.MemberNo;
- shareAmount = pl.SAmtDepo;
- shareBalance = pl.balance;
- ShareWithdrawn = pl.ShareWithdrawn;
- theiftFundAmount = pl.TAmtDepo;
- theiftFundInterest = pl.TInterest;
- GAmtDepo = pl.GAmtDepo;
- GInterest = pl.GInterest;
- DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
- Calendar cal = Calendar.getInstance();
- try{
- System.out.println("*****************INSERTING SHARE FUND DETAILS******************");
- sql = "INSERT INTO [dbo].[DetailsList] VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
- statement = conn.prepareStatement(sql);
- statement.setString(1, pl.EmNo);
- statement.setString(2, pl.MemberNo);
- statement.setString(3,"Share");
- statement.setLong(4, shareAmount);
- /*Date share_date = (Date) formatter.parse(new Date());*/
- statement.setLong(5,0);
- statement.setLong(6,pl.ShareWithdrawn);
- statement.setString(7,"Unknown");
- statement.setString(8,"OtherAmount for Share is The Withdrawn Share Amount");
- statement.setDate(9, pl.SDate);
- statement.setDate(10,null);
- statement.setLong(11, shareBalance);
- temp = statement.executeUpdate();
- if (temp != 0) {
- flag = true;
- System.out.println("ROW INSERTED SUCCESSFULLY");
- }
- } catch (Exception e) {
- System.out.println("Exception in Insert Details List Items");
- e.printStackTrace();
- }
- }
- Exception in Insert Details List Items
- com.microsoft.sqlserver.jdbc.SQLServerException: Invalid object name 'dbo.DetailsList'.
- at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:215)
- at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1635)
- at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:426)
- at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:372)
- at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:5846)
- at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1719)
- at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:184)
- at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:159)
- at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeUpdate(SQLServerPreparedStatement.java:315)
- at Test.insertDetailsList(Test.java:203)
- at Test.main(Test.java:290)
- sql = "INSERT INTO [dbo].[DetailsList] VALUES "
- + "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
- sql = "INSERT INTO [OrganizationMaster].[dbo].[DetailsList] VALUES "
- + "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
- use [Database Name]
- GO
- -------------------------------------------------------------------------------------------------------------------------
- --create new login in database for schema
- CREATE LOGIN [User Name] WITH PASSWORD=Nxxxxxxx
- GO
- --create new user in database for schema
- CREATE USER [User Name] FOR LOGIN [User Name] WITH DEFAULT_SCHEMA=[Schema Name]
- GO
- --grant permissions
- GRANT DELETE ON SCHEMA::[Schema Name] TO [User Name]
- GO
- GRANT INSERT ON SCHEMA::[Schema Name] TO [User Name]
- GO
- GRANT SELECT ON SCHEMA::[Schema Name] TO [User Name]
- GO
- GRANT UPDATE ON SCHEMA::[Schema Name] TO [User Name]
- GO
- GRANT REFERENCES ON SCHEMA::[Schema Name] TO [User Name]
- GO
- -------------------------------------------------------------------------------------------------------------------------
Add Comment
Please, Sign In to add comment