/**MySql数据库连接**/
String userName="root";
String userPwd="123123";
String dbName="test";
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url="jdbc:mysql:localhost/"+dbName+"?user="+userName+"&password="+userPwd;//dbName为数据库名
String user="system";//用户名
String pwd="admin";//密码
java.sql.Connection conn=DriverManager.getConnection(url,user,pwd);
/**Oracle数据库连接**/
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@localhost:1521:orcl"//orcl为数据库的SID(实例名)
String user="system";//用户名
String pwd="admin";//密码
java.sql.Connection conn=DriverManager.getConnection(url,user,pwd);
/**Sybase数据库连接**/
Class.forName("com.sybase.jdbc.SybDriver").newInstance();
String url="jdbc:sybase:Tds:localhost:5007/erp"//erp为数据库名
Properties sysProps=System.getProperties();
sysProps.put("user","sa");
sysProps.put("password","");
java.sql.Connection conn=DriverManager.getConnection(url,user,pwd);
/**DB2数据库连接**/
Class.forName("com.ibm.db2.jdbc.app.DB2Driver").newInstance();
String url="jdbc:db2://localhost:5000/sample"//sample为数据库名
String user="admin";
String pwd="";
java.sql.Connection conn=DriverManager.getConnection(url,user,pwd);
/**Informix数据库连接**/
Class.forName("com.informix.jdbc.IfxDriver").newInstance();
String url="jdbc:informix-sqli://localhost:1533/test:INFORMIXSERVER=infserver;"//test为数据库名
String user="admin";
String pwd="";
java.sql.Connection conn=DriverManager.getConnection(url,user,pwd);
/**Sql Server 2000数据库连接**/
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DataBaseName=db"//db为数据库名
String user="sa";
String pwd="111";
java.sql.Connection conn=DriverManager.getConnection(url,user,pwd);
/**Sql Server 2005数据库连接**/
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
String url="jdbc:sqlserver://localhost:1433;DataBaseName=db"//db为数据库名
String user="sa";
String pwd="111";
java.sql.Connection conn=DriverManager.getConnection(url,user,pwd);
/**PostgreSQL数据库连接**/
Class.forName("org.postgresql.Driver").newInstance();
String url="jdbc:postgresql://localhost/netdb"//netdb为数据库名
String user="root";
String pwd="123112";
java.sql.Connection conn=DriverManager.getConnection(url,user,pwd);
/**HSQLDB(Server) **/
Class.forName("org.hsqldb.jdbcDriver");
java.sql.Connection con = DriverManager.getConnection("jdbc:hsqldb:hsql://localhost:port/mydb","username","password");
/**access**/
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") ;
java.sql.Connection con=DriverManager.getConnection("jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=mdb的文件路径","username","password");
本文详细介绍了MySQL、Oracle、Sybase、DB2、Informix、SqlServer、PostgreSQL、HSQLDB、Access等数据库的连接方式,包括数据库名、用户名、密码等关键参数。
1万+

被折叠的 条评论
为什么被折叠?



