下载个sql数据库的jdbc驱动
并把该驱动加到classpath里
和其他的连接数据库没什么区别
并把该驱动加到classpath里
和其他的连接数据库没什么区别
解决方案 »
- 怎么去除两个数组中重复的字段 然后获得新的不重复的内容
- java.lang.AbstractMethodError: org.apache.xerces.dom.ElementNSImpl.setUserData
- 为什么连接不上mysql数据库?
- 请教struts数据源的配置
- hibernate取數據問題 在線等 解決給分
- 初学struts,求教关于jsp中struts标签的问题
- tomcat问题
- struts, validator问题,帮忙看看
- jbuilderx+jboss 写jsp编译时报 java.lang.NoClassdefFoundError.org
- 关于Struts的Action 类中的一些Method的问题 请大虾帮忙讲一些 谢谢?
- 对这个问题,我已经好几天不能解决,请大家帮忙呀!!
- ejb2.0里的local接口做什么的
当然在程序中,你还用针对你的库,作相应的修改。
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<html>
<body>
<%Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs";
//pubs为你的数据库的
String user="sa";
String password="";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from test";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()) {%>
您的第一个字段内容为:<%=rs.getString(1)%>
您的第二个字段内容为:<%=rs.getString(2)%>
<%}%>
<%out.print("数据库操作成功,恭喜你");%>
<%rs.close();
stmt.close();
conn.close();
%>
</body>
</html>
----
Connection connection = null;
try {
// Load the JDBC driver
String driverName = "oracle.jdbc.driver.OracleDriver";
Class.forName(driverName);
// Create a connection to the database
String serverName = "127.0.0.1";
String portNumber = "1521";
String sid = "mydatabase";
String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber + ":" + sid;
String username = "username";
String password = "password";
connection = DriverManager.getConnection(url, username, password);
} catch (ClassNotFoundException e) {
// Could not find the database driver
} catch (SQLException e) {
// Could not connect to the database
}
----注:如果从DS中取得就使用connection = ds.getConnection();这样。
void jButton1_actionPerformed(ActionEvent e)
{
try{
String strtmp="";
DriverManager.registerDriver(new SQLServerDriver());
Connection conn= DriverManager.getConnection
("jdbc:microsoft:sqlserver://hi3-rainy-peng;User=sa;Password=sa");
java.sql.Statement st=conn.createStatement();
ResultSet rs=st.executeQuery("select * from pubs.dbo.aaa");
while(rs.next())
{
strtmp +=(rs.getString(2))+"\n";
}
jtxtrTest.setText(strtmp);
}catch(SQLException ex)
{
System.out.println(ex);
}
}