java怎么连接sql server2019数据库

java怎么连接sql server2019数据库,第1张

找到相应版本的sql server版本的数据库驱动。

各个不同数据库厂家有自己对应的数据库驱动。

sqlserver的驱动一般是如下样子的:

mysql的驱动如下:

oracle的驱动如下:

postgreSQL的驱动如下:

这些驱动的获取都可以从网上开源的maven仓库中获取到

对了顺便再给你推荐一下常见maven仓库地址:

网页链接

看看你的数据库是否在你指定的地址上做监听

根据错误提示,显然是没有连接上指定的socket

同时你指出改为127001就OK,所以应该是无法连接到你指定的那个远程地址。

你试试telnet 一下远程的端口,看从本机是否能够访问,如果不行的话就把网络先调通再说

127001是不走网络的,而其它任何地址,哪怕 你指定的仍然是本机的另一地址(如19216801等),都是要走网络的

sqlserver2000与2005的jar文件不一样。

驱动类,还有连接语句都不一样。

驱动类:

commicrosoftjdbcsqlserverSQLServerDriver(sqlserver2000)

commicrosoftsqlserverjdbcSQLServerDriver(sqlserver2005)

连接语句:

jdbc:microsoft:sqlserver://<server_name>:<1433> (sqlserver2000)

jdbc:sqlserver://<server_name>:<1433>[;databaseName=<dbname>] (sqlserver2005)

如果都没有错可能是

javalangClassNotFoundException: commicrosoftjdbcsqlserverSQLSerDriver

中指出的你写的SQLSerDriver把它改成SQLServerDriver

应该是驱动的问题

你可能没有在你的工程中加载驱动包

你的数据库是sql sever2000 还是2005

如果是2000 执行数据库 *** 作 用这三个驱动是不行的 应该用jtdsjar这个驱动包

应该这样导入

try{

ClassforName("netsourceforgejtdsjdbcDriver");

Connection conn=DriverManagergetConnection("jdbc:jtds:sqlserver://localhost:1433;DatabaseName=","username","password");

System outprintln("Connection Succesful!");

}

catch (Exception e) {

eprintStackTrace();

}

}

基于blazeDS的flex4与spring的程序实例步骤

环境:

jdk16

j2ee15

spring256

blazeDS33

tomcat60

flex4

myeclipse85

flashBuilder4

步骤:

一、 启动好blazeDS(即启动tomcat,在[tomcat]/webapps目录下产生一个blazeds文件夹(三个war包产生一个blazeds文件夹));

在myeclipse85新建一个web Project工程,工程名为webSpring;

把此工程加入blazeDS支持(即用blazeds下的WEB-INF文件夹替换掉web工程下的WEB-INF文件夹);

加入spring支持(把spring相关的jar包拷贝到webSpring/WebRoot/WEB-INF/lib目录下即可)。

二、 1 在javaWeb工程webSpring的str目录下分别新建一下两个包:

cnxuediitmyFactory、cnxuediitmyService;

2 在cnxuediitmyFctory包下新建两个类:FlexFactoryImpljava和SpringFactoryInstancejava

(1) FlexFactoryImpljava:

package cnxuediitmyFactory;

import orgapachecommonsloggingLog;

import orgapachecommonsloggingLogFactory;

import flexmessagingFactoryInstance;

import flexmessagingFlexFactory;

import flexmessagingconfigConfigMap;

public class FlexFactoryImpl implements FlexFactory {

private Log log = LogFactorygetLog(getClass());

/override interface method/

public void initialize(String id, ConfigMap configMap) {

Systemoutprintln("1---flex工厂实现类重写的方法initialize");

}

/override interface method/

public FactoryInstance createFactoryInstance(String id, ConfigMap properties) {

Systemoutprintln("2---flex工厂实现类重写的方法createFactoryInstance");

loginfo("Create FactoryInstance");

SpringFactoryInstance instance = new SpringFactoryInstance(this, id, properties);

instancesetSource(propertiesgetPropertyAsString(SOURCE, instancegetId()));

return instance;

}

/override interface method/

public Object lookup(FactoryInstance instanceInfo) {

Systemoutprintln("4---flex工厂实现类重写的方法lookup");

loginfo("Lookup service object");

return instanceInfolookup();

}

}

(2)SpringFactoryInstancejava

package cnxuediitmyFactory;

import orgapachecommonsloggingLog;

import orgapachecommonsloggingLogFactory;

import orgspringframeworkbeansBeansException;

import orgspringframeworkbeansfactoryNoSuchBeanDefinitionException;

import orgspringframeworkcontextApplicationContext;

import orgspringframeworkwebcontextsupportWebApplicationContextUtils;

import flexmessagingFactoryInstance;

import flexmessagingFlexContext;

import flexmessagingFlexFactory;

import flexmessagingconfigConfigMap;

import flexmessagingservicesServiceException;

public class SpringFactoryInstance extends FactoryInstance {

private Log log = LogFactorygetLog(getClass());

SpringFactoryInstance(FlexFactory factory, String id, ConfigMap properties) {

super(factory, id, properties);

}

public Object lookup() {

Systemoutprintln("3---spring工厂类的方法lookup");

ApplicationContext appContext = WebApplicationContextUtilsgetRequiredWebApplicationContext(FlexContextgetServletConfig()getServletContext());

String beanName = getSource();

try {

loginfo("Lookup bean from Spring ApplicationContext: " + beanName);

return appContextgetBean(beanName);

} catch (NoSuchBeanDefinitionException nex) {

ServiceException e = new ServiceException();

String msg = "Spring service named '" + beanName + "' does not exist";

esetMessage(msg);

esetRootCause(nex);

esetDetails(msg);

esetCode("ServerProcessing");

throw e;

} catch (BeansException bex) {

ServiceException e = new ServiceException();

String msg = "Unable to create Spring service named '" + beanName + "'";

esetMessage(msg);

esetRootCause(bex);

esetDetails(msg);

esetCode("ServerProcessing");

throw e;

} catch (Exception ex) {

ServiceException e = new ServiceException();

String msg = "Unexpected exception when trying to create Spring service named '" + beanName + "'";

esetMessage(msg);

esetRootCause(ex);

esetDetails(msg);

esetCode("ServerProcessing");

throw e;

}

}

}

3 在cnxuediitmyService包下新建两个类:FServicejava和FServicesImpljava

(1) FServicejava

package cnxuediitmyService;

public interface FService {

public String sayHello(String name);

}

(2) FServicesImpljava

package cnxuediitmyService;

public class FServicesImpl implements FService {

public String sayHello(String name) {

Systemoutprintln("5---服务层实现类(本质上的与flex交互的类)");

return "我是服务层的服务实现类==" + name;

}

}

三、 1、 在javaWeb工程webSpring下,在文件webSpring/WebRoot/WEB-INF/webxml的<web-app>标签下添加子节点:

<listener>

<listener-class>

orgspringframeworkwebcontextContextLoaderListener

</listener-class>

</listener>

2、 在javaWeb工程webSpring下,在webSpring/WebRoot/WEB-INF目录下新建一个文件:applicationContextxml

<xml version="10" encoding="UTF-8">

<beans xmlns=">

sqlServer版本是什么

2000加载驱动和URL的语句是

String driverName = "commicrosoftjdbcsqlserverSQLServerDriver";

String dbURL = "jdbc:microsoft:sqlserver://localhost:1433; DatabaseName=XXX";

SQL Server 2005 中加载驱动和URL的语句是

String driverName = "commicrosoftsqlserverjdbcSQLServerDriver";

String dbURL = "jdbc:sqlserver://localhost:1433; DatabaseName=XXX";

如果写法错误将会找不到驱动。

用JDBC-ODBC桥来连接SQLServer比较简单,代码如下:

public void class{

Connection con;

Statement st;

Resultset rs;

int count;

try{

Classforname("sunjdbcodbcjdbcodbcDriver");

con=DriverManger("jdbc:odbc:conndb","sa","pwd");

//conndb是你的数据库名称,sa 是数据库登陆用户名,pwd是登陆密码

st=concreateStatement;

}catch(exception e){

Systemoutprintln(e);

}

public ResultSet select(String sql){

rs=stexcuteQuery(sql);

}//这个方法用于在数据库中进行查询,里面要加try{}catch()

public int update(String sql){

count=stexcuteUpdate(sql);

}//这个方法用于在数据库中进行增、删、改

}

以上就是关于java怎么连接sql server2019数据库全部的内容,包括:java怎么连接sql server2019数据库、Java如何连接远程数据库(sql server 2000)、java连接SQLServer2000数据库等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/9303354.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-27
下一篇 2023-04-27

发表评论

登录后才能评论

评论列表(0条)

保存