Mr Mirchi Posted October 30, 2012 Report Posted October 30, 2012 evaranna jdbc connection sql server meeda chesaraaa? if so,[list=1] [*]Connection connection = DriverManager.getConnection( "jdbc:sqlserver://localhost:1433;[b]databaseName=EMPLOYEE;selectMethod=cursor[/b]", "username", "password"); [/list] java code lo databaseName emi avuthumdi? nenu vere team vallaa sql server connect avvaali java numdi...maadi emo oracle server le. vere team vaalu ..just server name, port, username/password only ichaaru........toad numdi..I m able to connect..
vishwak Posted October 30, 2012 Report Posted October 30, 2012 Ask the other team for sql server name, port, database name and then you replace local host with SQL server name, 1433 with the port number and database name with the database name provided. thats your JDBC connection.
ChampakDas Posted October 30, 2012 Report Posted October 30, 2012 'serverName' anna parameter aa kanipichatledhu naku aa connection string lo...add that
ICANWIN Posted October 30, 2012 Report Posted October 30, 2012 import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class SimpleConnectionHandler { Connection conn = null; private void initConn() throws ClassNotFoundException, SQLException { Class.forName("oracle.jdbc.driver.OracleDriver"); final String DB_URL="whatever:1800/servicename"; final String DB_USER= "username"; final String DB_PASS="password"; String url = "jdbc:oracle:thin:@//"+ DB_URL; conn = DriverManager.getConnection(url, DB_USER, DB_PASS); conn.setAutoCommit(false); } public Connection getConn() { int retryCount = 1; try { while (conn == null || conn.isClosed()) { System.out.println("DataBase connection apptempt -- " + retryCount); try { initConn(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SQLException e) { System.out.println("DataBase connection apptempt -- " + retryCount + " FAILED"); } retryCount++; if (retryCount > 4) break; } if (retryCount > 4) { System.out.println("All conection apptempts failed, check DB params,"); } else { System.out.println("DataBase connection established"); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return conn; } public void closeConn() throws SQLException { if (conn != null || !conn.isClosed()) conn.close(); } } this is working code ..change values are try..
CQ5_DEV Posted October 30, 2012 Report Posted October 30, 2012 [quote name='ICANWIN' timestamp='1351615593' post='1302711253'] import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class SimpleConnectionHandler { Connection conn = null; private void initConn() throws ClassNotFoundException, SQLException { Class.forName("oracle.jdbc.driver.OracleDriver"); final String DB_URL="whatever:1800/servicename"; final String DB_USER= "username"; final String DB_PASS="password"; String url = "jdbc:oracle:thin:@//"+ DB_URL; conn = DriverManager.getConnection(url, DB_USER, DB_PASS); conn.setAutoCommit(false); } public Connection getConn() { int retryCount = 1; try { while (conn == null || conn.isClosed()) { System.out.println("DataBase connection apptempt -- " + retryCount); try { initConn(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SQLException e) { System.out.println("DataBase connection apptempt -- " + retryCount + " FAILED"); } retryCount++; if (retryCount > 4) break; } if (retryCount > 4) { System.out.println("All conection apptempts failed, check DB params,"); } else { System.out.println("DataBase connection established"); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return conn; } public void closeConn() throws SQLException { if (conn != null || !conn.isClosed()) conn.close(); } } this is working code ..change values are try.. [/quote] sql server ante jdbc oracle thin antav enti
CQ5_DEV Posted October 30, 2012 Report Posted October 30, 2012 [quote name='Mr Mirchi' timestamp='1351612992' post='1302710953'] evaranna jdbc connection sql server meeda chesaraaa? if so,[list=1] [*]Connection connection = DriverManager.getConnection( "jdbc:sqlserver://localhost:1433;[b]databaseName=EMPLOYEE;selectMethod=cursor[/b]", "username", "password"); [/list] java code lo databaseName emi avuthumdi? nenu vere team vallaa sql server connect avvaali java numdi...maadi emo oracle server le. vere team vaalu ..just server name, port, username/password only ichaaru........toad numdi..I m able to connect.. [/quote] heights bhayya nuvvu adigina question... databasename lekunda denitho connection pettukovalo ela telustadi mirchi u cant..poyi vallani dbname adugu
dotnetrockz Posted October 30, 2012 Report Posted October 30, 2012 [url="http://www.connectionstrings.com/"]http://www.connectionstrings.com/[/url]
ICANWIN Posted October 30, 2012 Report Posted October 30, 2012 [quote name='CQ5_DEV' timestamp='1351616061' post='1302711307'] sql server ante jdbc oracle thin antav enti [/quote] values kuda marchi ivvala enti...
ICANWIN Posted October 30, 2012 Report Posted October 30, 2012 [quote name='CQ5_DEV' timestamp='1351616445' post='1302711349'] heights bhayya nuvvu adigina question... databasename lekunda denitho connection pettukovalo ela telustadi mirchi u cant..poyi vallani dbname adugu [/quote] Db hostname, portnumber,service name,username and password adugu...connection details tesuko 1st...schema name is not necessaryy...oka vela application properties nunchi a parameter dynamic ga vaste u wont specify here...query lo directly variable declare chesi you use it with query.. say schema name is XXX select * from XXX.table1 where column name = 'ddjjkd';
Mr Mirchi Posted October 30, 2012 Author Report Posted October 30, 2012 [quote name='CQ5_DEV' timestamp='1351616445' post='1302711349'] heights bhayya nuvvu adigina question... databasename lekunda denitho connection pettukovalo ela telustadi mirchi u cant..poyi vallani dbname adugu [/quote] ok...listen.... servername is diff from database name....in the url connection....servername is localhost/your ip if you are running the sql server on your local server.....naa question abt database name paramter ........ after bit of research..found that databasename is optional and servername is as i said and mentioned in the post.
CQ5_DEV Posted October 30, 2012 Report Posted October 30, 2012 [quote name='Mr Mirchi' timestamp='1351620031' post='1302711778'] ok...listen.... servername is diff from database name....in the url connection....servername is localhost/your ip if you are running the sql server on your local server.....naa question abt database name paramter ........ after bit of research..found that databasename is optional and servername is as i said and mentioned in the post. [/quote] research kadu. nuvvu try chesaka okasari cheppu malli. last time nenu sql server ki dbname ivvaka pote connection establish avaledu. okasari try chesi malli cheppu bhayya...nerchukunta
ICANWIN Posted October 30, 2012 Report Posted October 30, 2012 [quote name='CQ5_DEV' timestamp='1351621461' post='1302711951'] research kadu. nuvvu try chesaka okasari cheppu malli. last time nenu sql server ki dbname ivvaka pote connection establish avaledu. okasari try chesi malli cheppu bhayya...nerchukunta [/quote] It should work without database name ideally endukante prod,UAT lo different branch lo different schemas untayi...same hard code ala chestav if u give in connection? same code kada copy chestaru vere branch ki? every time velli em name change cheyam kada? It's been a while i worked on SQL Server but i think it should work without schema name... ex: prod---XXX schema UAT Oct branch -- xxx_Oct dec --- xxx_dec
CQ5_DEV Posted October 30, 2012 Report Posted October 30, 2012 [quote name='ICANWIN' timestamp='1351621761' post='1302712000'] It should work without database name ideally endukante prod,UAT lo different branch lo different schemas untayi...same hard code ala chestav if u give in connection? same code kada copy chestaru vere branch ki? every time velli em name change cheyam kada? It's been a while i worked on SQL Server but i think it should work without schema name... ex: prod---XXX schema UAT Oct branch -- xxx_Oct dec --- xxx_dec [/quote] mutiple env's lo hardcode cheyavu. properties lo store chestav. hibernate / spring jdbc / normal .properties file lo/ build scripts/ CI server lo...ala anamata usual ga dbname empty undakudadu enterprise dev lo. good practice. but last time nenu sql server ki dbname ivvaledu. default namespace teesukuntundi le ani..but that did not work. so anduke adiga..
Recommended Posts