好像不行啊java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
我用mysql的odbc没有问题, 请检查sql server
的数据源及其权限
<%@ page import = "java.sql.*" %>
<%
String url = "jdbc:odbc:mysql";
String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
try{
Class.forName(driver);
java.sql.Connection conn = DriverManager.getConnection(url,"wushilin","******");
Statement s = conn.createStatement();
s.executeUpdate("insert into test values('asdf')");
ResultSet rs = s.executeQuery("select * from test");
while(rs.next())
{
out.println(rs.getString(1)+"<br>");
}
rs.close();
s.close();
conn.close();
}
catch(Exception e)
{
System.err.println("Error");
}
%>
output:
test
test
test
asdf
asdf
asdf
asdf
<%@ page import = "java.sql.*" %>
<%
String url = "jdbc:odbc:mysql";
String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
try{
Class.forName(driver);
java.sql.Connection conn = DriverManager.getConnection(url,"wushilin","******");
Statement s = conn.createStatement();
s.executeUpdate("insert into test values('asdf')");
ResultSet rs = s.executeQuery("select * from test");
while(rs.next())
{
out.println(rs.getString(1)+"<br>");
}
rs.close();
s.close();
conn.close();
}
catch(Exception e)
{
System.err.println("Error");
}
%>
output:
test
test
test
asdf
asdf
asdf
asdf