* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download Draw Back of jdbc Connectivity
Survey
Document related concepts
Transcript
JdbcSqlserver connectivity import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; public class ConnectMSSQLServer { public void dbConnect(String db_connect_string, String db_userid, String db_password) { try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); Connection conn = DriverManager.getConnection(db_connect_string, db_userid, db_password); System.out.println("connected"); Statement statement = conn.createStatement(); String queryString = "select * from sysobjects where type='u'"; ResultSet rs = statement.executeQuery(queryString); while (rs.next()) { System.out.println(rs.getString(1)); } } catch (Exception e) { e.printStackTrace(); } } public static void main(String[] args) { ConnectMSSQLServer connServer = new ConnectMSSQLServer(); connServer.dbConnect("jdbc:sqlserver://<hostname>", "<user>", "<password>"); } } Jdbcmysql connectivity import java.sql.*; public class MysqlConnect{ public static void main(String[] args) { System.out.println("MySQL Connect Example."); Connection conn = null; String url = "jdbc:mysql://localhost:3306/"; String dbName = "jdbctutorial"; String driver = "com.mysql.jdbc.Driver"; String userName = "root"; String password = "root"; try { Class.forName(driver).newInstance(); conn = DriverManager.getConnection(url+dbName,userName,password); System.out.println("Connected to the database"); conn.close(); System.out.println("Disconnected from database"); } catch (Exception e) { e.printStackTrace(); } } } Draw Back of jdbc Connectivity 1. 2. 3. 4. 5. In JDBC, if we open a database connection we need to write in try, and if any exceptions occurred catch block will takers about it, and finally used to close the connections. Actually if we didn’t close the connection in the finally block, then jdbc doesn’t responsible to close that connection In JDBC we need to write Sql commands in various places, after the program has created if the table structure is modified then the JDBC program doesn’t work, again we need to modify and compile and re-deploy required, which is tedious JDBC used to generate database related error codes if an exception will occurs, but java programmers are unknown about this error codes right. In the Enterprise applications, the data flow with in an application from class to class will be in theform of objects, but while storing data finally in a database using JDBC then that object will be converted into text. Because JDBC doesn’t transfer objects directly.