能书写,通过JDBC连接Oracle的一个小程序吗
1个回答
展开全部
实现思路:就是通过ojdbc.jar中提供的方法,直接连接数据库即可,固定代码写法如下:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.Statement; public class JDBCTest {public static void main(String[] args) throws Exception {//1.加载驱动//Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");//Class.forName("com.mysql.jdbc.Driver");Class.forName("oracle.jdbc.driver.OracleDriver"); //2.创建数据库连接对象//Connection conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=db","sa","sqlpass");//Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useUnicode=true&characterEncoding=UTF-8","root","123456");Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","Oracle123");
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.Statement; public class JDBCTest {public static void main(String[] args) throws Exception {//1.加载驱动//Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");//Class.forName("com.mysql.jdbc.Driver");Class.forName("oracle.jdbc.driver.OracleDriver"); //2.创建数据库连接对象//Connection conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=db","sa","sqlpass");//Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useUnicode=true&characterEncoding=UTF-8","root","123456");Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","Oracle123");
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询